Skip to content

Instantly share code, notes, and snippets.

@parwatcodes
Created April 3, 2017 09:15
Show Gist options
  • Save parwatcodes/7d9e0ff0482a27d8b86b1eb1b53b4f61 to your computer and use it in GitHub Desktop.
Save parwatcodes/7d9e0ff0482a27d8b86b1eb1b53b4f61 to your computer and use it in GitHub Desktop.
app.post('/users', function(req, res) {
var user = new User({
username: req.body.username
});
user.save(function(err) {
if (err) {
if (err.name === 'MongoError' && err.code === 11000) {
// Duplicate username
return res.status(500).send({ succes: false, message: 'User already exist!' });
}
// Some other error
return res.status(500).send(err);
}
res.json({
success: true
});
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment