I want to have login/register function in my expressJS API. So now im just inserting password and email into my database, i want this function to first check if user with this email is already in database - if yes, send response that user is logged. If not, just insert him to database. Is it possible to handle some errors in here?
I already have it:
exports.login = function(req, res){
var email = req.body.email;
var pwd = req.body.pass;
db.collection('users', function(err, collection) {
collection.insert({login:email, password: pwd}, {safe:true}, function(err, result) {
res.send("OK");
});
});
};\
and dont know what's next.