简体   繁体   中英

i am not able to get the data throught below code in nodejs ? it shows TypeError: Converting circular structure to JSON

app.get('/students', (req, res)=>{
 const studentsData = Student.find();
 studentsData.then(()=>{
    res.status(200).send(studentsData);
   }).catch((e)=>{
    console.log(e);
    res.status(400).send(e);
  })
  })

I am getting error says that :- TypeError: Converting circular structure to JSON

You should use the result of the promise to send back, instead of the promise itself:

app.get('/students', (req, res)=>{
 const studentsData = Student.find();
 studentsData.then(result => {
    res.status(200).send(result);
 }).catch((e)=>{
  console.log(e);
  res.status(400).send(e);
 })
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM