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.