Quantcast
Channel: node.js require files globally - Stack Overflow
Viewing all articles
Browse latest Browse all 2

node.js require files globally

$
0
0

I have a problem which i would like to get help with here on stackoverflow.

In my node.js project i have a init.js file which i want to do the following

pseudo code

var variable = require(folder/file).name; (of exported module)var variable2 = reuire(folder2/file2).name; (of exported module)variable2.init();

in my init function i am trying to use my var (which in this dummy case) called variable. My catch returns the error that the var called variables is not found. i found that if i use global.variable = require.... then the stuff would work. I though doubt that this is a good way to work in node.js

Why do i want to do it this way? because in my variable2 functions i require other stuff which my variable1 functions is needed (and my init.js is on super top in these layers).

Any tips or help on how to either fix this or structure things better ?


Viewing all articles
Browse latest Browse all 2

Trending Articles





<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>