Reputation: 824
New to Node.js, and Im wondering if it's possible to pass a parameter to a module function? Something similar to this:
module.js:
module.exports = {
example1: function(parameter) {
return "hello, world";
},
example2: function(parameter) {
return "hello,world";
}
};
Then call it like so...
var mod = require("./module.js")
mod.example1(passedParameter);
Thanks!
Upvotes: 0
Views: 96
Reputation: 708026
A function attached as an exported property as shown in your answer is just a function like any other function. You decide what arguments you want it to accept and process and what arguments to pass it. It's just like any other Javascript function definition - you decide how to define and use it. The fact that it's an exported property from a module does not make any difference. It's just a Javascript function like any other. It happens to live in a particular module, but other than that, you can do anything with it that you can with any other function definition.
I'm wondering if it's possible to pass a parameter to a module function?
Yes, it is possible and is common.
Upvotes: 2