User2013
User2013

Reputation: 409

Node module.exports reference own function like this keyword?

I have the following code:

module.exports.functionA = function(str) {
     console.log(str);
}

In the same module, how do I call functionA? In other languages such as PHP, you can call another member of the same class using $this->functionA();

This does not work:

module.exports.functionA('Hello world!');

Upvotes: 0

Views: 723

Answers (1)

User2013
User2013

Reputation: 409

When functionA was assigned to module.exports it was still undefined. Instead do:

var functionA = function(str) {
    console.log(str);
}

module.exports = {
    functionA: functionA
}

Then the following will work:

module.exports.functionB = function() {
     functionA('Hello world!');
}

Upvotes: 4

Related Questions