Answer the question
In order to leave comments, you need to log in
Why is it impossible to get and give module.exports in one file?
There is a module to which, when connected, a function / variable is passed, for example, like this: myModule = require('./mymodule')(param);
In the module, the variable is received like this:
var param;
module.exports = function(item){
param = item;
}
echo = function(){
console.log('ok');
}
module.exports.echo = echo;
myModule.echo();
Answer the question
In order to leave comments, you need to log in
mymodule.js
var param = "param";
module.exports = function(item){
var self = this;
param = item;
self.echo = function(){
console.log(param);
}
return {
echo: self.echo
}
}
var myModule = require('./mymodule')("newparam");
myModule.echo();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question