I'm using Expressjs w/ node.js and I have a route like this:
users.init(app.db, function() {
users.checkUsername(user.username, function(err, count) {
if (count > 0) {
res.json({'username': 'unavailable'});
}
});
users.checkEmail(user.email, function(err, count) {
if (count > 0) {
res.json({'email': 'unavailable'});
}
});
users.insertUser(user, function(err, response) {
res.json({'success' : 'true'});
});
})
This will print send multiple responses, username and email for example, in some cases.
This route is being called via ajax, in php, I normally do an exit() after I echo out a json response. Is there a way to do that in Expressjs?
Thank you!
EDIT: I could wrap everything in if/else or set a flag inside each, but just seeing if there's a more elegent way.