0

The following code is written in NodeJS. I have a controller file as below,

var Controller = function(){

  var lib = require('../libraries/common').Common;

  this.name = "somename";
  this.id = lib.getId(this.name);

}

And in the common.js file the code is as follows,

var Common = function(){

  var Tool = require('../models/tools').Tools;

  this.getId = function(name){
    Tool.findOne({name: name},function(err, tool){
      console.log("tool = "+tool);  
    });
  }

}
module.exports.Common = new Common();

How do I achieve this? I want the value returned from the common.js to my controller. Is there any other way other than using async or callbacks? Please let me know if it is possible. Thanks in advance.

Manjunath Singh
  • 95
  • 3
  • 10

0 Answers0