Node.js Bug Hunt Easy +10 XP
Missing Await
This async route doesn't wait for the database.
Node.jsFind the bug
1
app.get("/users", async (req, res) => {2
const users = User.find();3
res.json(users);4
}); The bug is on line 2
Select the correct fix
Show answer and explanation
Answer: Add await before User.find()
User.find() returns a Promise. Without await, users is a Promise object, not the actual data.
Hint: Mongoose queries return Promises.
What this challenge tests
Bug Hunt in Node.js: async, mongoose.