node.js - how to return a value or string from call back function in Nodejs, mongooose -


i have function inserting user credentials. want return value call function...

    var router = require('express').router();      var user = require('../models').users;      // function calling here      router.post('/signup', function (req, res)       {         var result = user.signup(req.body);         res.send(result);     });  module.exports = router;   //implemetation of function  userschema.statics.signup = function signup(obj) {   var user = new usermodel(obj);      user.password = hash.generate(obj.password);      return user.save(function (err, newuser) {         if (err)          {             return 'error occured during insertion..';         } else          {             return 'you have sign successfully...';         }     }); } 

i want return response string showing undefined. how should done?

var router = require('express').router();  var user = require('../models').users;    router.post('/signup', function (req, res)   {      var result = user.signup(req.body, function(err, result){        if(err){        }        else{          res.send(result)       }     });  });  userschema.statics.signup = function signup(obj, callabck) {  var user = new usermodel(obj);     user.password = hash.generate(obj.password);     user.save(function (err, newuser) {         if (err)          {             callback( 'error occured during insertion..');         } else          {             callback(null, newuser);         }     }); } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -