0

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
}
})

1 Answer 1

1

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);
  }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.