Here's my code:
app.post('/register', function(req, res){
var user = new User(req.body);
if (req.body.password.length <= 5){ res.status(400).send('error: password must be longer'); }
if (req.body.username.length <= 3){ res.status(400).send('error: username must be longer'); }
User.findOne({
username: req.body.username
}, function(err, userr){
if(err) {res.status(400).send(err); }
if (userr){res.status(400).send('error: user already exists'); }
user.save(function(err, user){
if (err){ res.status(400).send('couldn\tt save fo sum rezon'); }
if (user) { res.send(user); }
});
});
});
Here's my error:
home/michael/passport-local-implementation/node_modules/mongoose/node_modules/mpromise/lib/promise.js:108
if (this.ended && !this.hasRejectListeners()) throw reason;
^
Error: Can't set headers after they are sent.
I'm confused about where I'm sending headers more than once? Shouldn't this code stop executing as soon as one of the conditionals are met, or if none are met, then just render the user?
Bonus points if anyone can give me resources on where to read up on the finer points of how express routing works!