Skip to content

Instantly share code, notes, and snippets.

@matmar10
Last active August 29, 2015 14:12
Show Gist options
  • Save matmar10/be30daa99cd2d8217a00 to your computer and use it in GitHub Desktop.
Save matmar10/be30daa99cd2d8217a00 to your computer and use it in GitHub Desktop.
Express.js middleware the hard way
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