node.js - In node js how to get the result of the other module method in current module -
moduletwo.js
exports.getnotificatiosbyid = function (notificationid) { db.get(notificationid, function (err, doc) { if(!err){ return true; } }); }; in modulelone need result of moduletwo method.if moduletwo method doesn't have database query function means can method result below in moduleone
var res=require('./lib/moduletwo').getnotificatiosbyid; if db.get method has synchronize method means can query
db.getsync(id); is there other way result of moduletwo method.now i'm trying below.is correct
moduleone.js
var moduletwo=require('./lib/moduletwo'); moduletwo.getnotificatiosbyid(id,function(err,res){ if(!err){ console.log('result of 2nd module '+res); } });
you need change getnotificatiosbyid take callback
exports.getnotificatiosbyid = function (notificationid,callback) { db.get(notificationid, function (err, doc) { if(!err){ callback(doc); return true; } }); }; then call like
var moduletwo=require('./lib/moduletwo'); moduletwo.getnotificatiosbyid(id,function(res){ console.log('result of 2nd module '+res); });
Comments
Post a Comment