I am writing a module for node.js and one file is not enough. I want to connect the submodule to the current module's namespace. Something of type include in c ++. How do I change the code to make it work?

variables.js:

var a = 3; 

index.js:

 console.log(a); 
  • If you do through require, you will need to contact through an intermediate object, and this is not very convenient. - rewardealer
  • require is the only way, because each file in node.js creates a separate, isolated scope for it - Dmitriy Simushev
  • @Dmitriy, tell me, is there an object in node.js that is responsible for the current visibility? If so, then we can run through all the members of the submodule and assign this object the entire content of the submodule. This can be done with globals, but it would be foolish to litter it. I found a way to merge all the objects of all the subfiles into one: gist.github.com/matteocontrini/2da2f6ceefbaa3ea9384 - rewardealer
  • @Fixturessd yes, you can access the current scope using this - Darth

0