node.js - Is it a right way to response when query database? -


i use express , mysql node-orm2.

there request data database.

var loginformchecker = function (phone, pwd, cb) {     var ret = {};      userbasemodel.exists({         phone: phone,         password: pwd     }, function (err, exists) {         if (err) {             // database error             ret = new returndata({                 error: error.database,                 type: 0             });         } else {             ret = new returndata({                 data: exists,                 type: 1             });         }          cb(ret);     }); };  router.route('/login') .get(function (req, res) {     var query = req.query;      var output = function (ret) {         if (ret) {             res.send(ret);         } else {             res.status(500).send('something broken!');         }     };      userservice.loginformchecker(query.p, query.k, output); }); 

i pass output function loginformchecker, , call in callback of querying data.

i not know whether right way it. there better way do, maybe promise or something?

thanks.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -