Last active
August 29, 2015 14:12
-
-
Save matmar10/be30daa99cd2d8217a00 to your computer and use it in GitHub Desktop.
Express.js middleware the hard way
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.post('/user/:id', function (req, res) { | |
User.findOne({_id: ObjectId(req.params.id)}, function (err, user) { | |
validator.run(rules, req.body, function (errorCount, errors) { | |
user.merge(req.body); | |
user.save(function(err, savedUser) { | |
EmailClient.sendEmail(user.email, 'Your account was updated', function (err) { | |
res.status(200).send({ | |
message: 'User updated' | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment