Created
April 3, 2017 09:15
-
-
Save parwatcodes/7d9e0ff0482a27d8b86b1eb1b53b4f61 to your computer and use it in GitHub Desktop.
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('/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