Reputation: 348
I am trying to fetch data from Mongodb and i want that data to show up on my web page.The problem is i don't know how to send the whole fetched object to a specific port (the response) so that i'll be able to fetch it from Angular and how will i be able to access data from Angular
Fetching data from Mongodb
app.get('/api/getdata',async (req,res) =>
{
const {value} = req.body
const resp=await person.find({value})
if(!resp){
console.log('not found')
}
else{
//this needs to be done
}
})
Upvotes: 0
Views: 613
Reputation: 696
Please, have a look at express API reference
then your code would look like :
app.get('/api/getdata', async (req,res) => {
const {value} = req.body
const resp = await person.find({value})
if (!resp) {
res.status(404).send('not found')
}else{
// give your data to express response to the http request
res.json(resp); // or res.send(resp);
}
});
Upvotes: 1