The problem with what you did is that you set the variable after import, but this.myvariable === 'test'; called when the module was imported before your variable was set.
You can configure the module to function, and then call the function upon import, passing the variable as an argument.
module.exports = function(myVar) { var myModule = {
Upon import
var myModule = require('myModule')(myVar);
If you use this method, keep in mind that you get another instance of your module, wherever you import, which may not be what you want.
If you want to set module values ββfrom outside the module, a good option is for your module to export the object using the setter method and use it to set the value of the variable as an object property. This makes it clearer that you want this value to be customizable, while just executing myModule.myVar = can lead to confusion later on.
module.exports = { myVar: null, setMyVar: function(myVar) { this.myVar = myVar; }, ... };
In this case, you get access to the same instance of the model, wherever you import it.
Edit in response to comment
In the first option, you show where you get a different instance every time, how can I export several functions, each of which has the same MYVAR? If this module exports 5 functions, each of which needs myVar, can I install it in one place, like during import, and not pass it to each function?
Not quite sure if I understand what you are describing, but you can do something like this:
module.exports = function(myVar) { var modules = {}; modules.someModule = {...}; modules.anotherModule = {...}; ... return modules; };
Each of these submodules will have access to the same myVar. Therefore, you must import as described above, and the result will be an object containing each of your five modules as properties. I canβt say if this is a good idea, it is becoming rather confusing, but maybe this makes sense for your situation.