When I make a POST request, I found out that it will give me the entire data base even though I just want one entry. Here is the code
app.get("/api/users", (req, res) => {
User.find({}, (e, dt) => {
if(e){
//Easier to debug
res.send('There was an error related to user search')
console.log(e)
} else if (!dt) {
res.send('No such user exists')
}else{
res.json(dt)
console.log(`This will log out even though I am doing a POST request and not a GET one`)
}
})
})
app.post("/api/users", (req, res) => {
const newUser = new User({
username: req.body.username
})
newUser.save((e, dt) => {
if (e) console.log(e)
else res.json(dt)
})
})