0

I'm making a POST request like this:

router.post('/register2', (req, res) => {
    const newUser = new User({
                    name: req.body.name,
                    email: req.body.email,
                    password: req.body.password
                });
                newUser.save()
                    .then(res.json(newUser));
})

But, in Postman, no matter what I enter for my name/email/password values, it just returns the first set of values I ever tried. The id and date update each time, but name, email, and password ignore the input and give me the same things every time.

Here's the "User" that newUser refers to:

const UserSchema = new Schema({
    name: {
        type: String,
        required: true
    },
    email: {
        type: String,
        required: true
    },
    password: {
        type: String,
        required: true
    },
    date: {
        type: Date,
        default: Date.now
    }
});

module.exports = User = mongoose.model('users', UserSchema);
Nick Tamburro
  • 150
  • 1
  • 4
  • 16
  • 1
    Did you check if you are actually receiving the values you're posting? Try logging `req.body` to see if you are, and if you aren't you may be missing the body parser middleware, see https://stackoverflow.com/questions/5710358/how-to-retrieve-post-query-parameters – ruedamanuel Oct 12 '18 at 19:17
  • @ruedamanuel This seems like a step in the right direction. I do have body-parser working, but when I log the req.body it shows me these same old values that keep posting, rather than the new values I'm entering. – Nick Tamburro Oct 12 '18 at 19:24
  • I was misusing Postman. I was passing my new values under the Params tab, while the Body tab was still filled with my old values. – Nick Tamburro Oct 12 '18 at 22:20

0 Answers0