I have several post methods in node. One of them works, now I am working on the other. I've tried switching the order of the key-value pairs in the res.body, restarting my backend server, and a few other things, and now I am out of ideas. I am using postman so maybe an issue with that, but maybe you guys will see an obvious error that I don't.
Here's the model:
var UserGameSchema = new mongoose.Schema({
user: { type: String, required: true },
game: { type: String, required: true },
own: { type: Boolean, required: true }
});
var UserGame = mongoose.model('UserGame', UserGameSchema);
module.exports.UserGame = UserGame;
here's my method:
app.post('/mygames', function(req, res) {
UserGame.create({
user: req.body.user,
game: req.body.game,
own: req.body.own
}, function(err, item) {
if (err) {
return res.status(500).json({
message: 'Internal Server Error'
});
}
res.status(201).json(item);
});
});
and here is the res.body I am sending using Postman
{
"user": "Colin",
"own": true,
"game": "Grand Theft Auto 5 (PS4)"
}
Yes, I am pretty sure I am using the correct URL: http://localhost:8080/mygames
still getting this 500 error. Specifically postman is returning in the console:
TypeError: Cannot read property 'user' of undefined
Im not sure why user would be undefined.
Thanks for any feedback.
If looking for way too much info, here is the github repo for this: https://github.com/auldsy-ababua/gameswap