0

I am trying to use a function in another module i am not able to use it may i know what is the issue?

 this.test = function(callback) {
        callback('i am test');
    };
    module.exports.config = function (settings, callback) {
    this.test(function(err,res){
    console.log(res);
    });
    };

1 Answer 1

1

The value of this is different because you're inside another function. Try this instead:

this.test = function(callback) {
  callback('i am test');
};
var self = this;
module.exports.config = function (settings, callback) {
  self.test(function(err,res){
    console.log(res);
  });
};

Or just give the function name and call it directly:

function test(callback) {
  callback('i am test');
};
module.exports.config = function (settings, callback) {
  test(function(err,res){
    console.log(res);
  });
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.