Answer the question
In order to leave comments, you need to log in
Node.js: How bad is it to use a global object?
Node.js has a global object.
I would like to have some kind of bootstrap file that would read configs, parse command line parameters. Roughly speaking initialized entirely application.
in any of the files used inside, I want to be able to access the config. One of the solutions is to push some object into the global in the bootstrap file (for example, index.js), for example
global.app = {
config: {...},
somethingElse: {...}
}
Answer the question
In order to leave comments, you need to log in
I think that this is a good practice if you have your object named as an application, etc., so that if anything, no one intersects with it.
If any of the modules of your application wants to be reused (for you or someone else, and modular programming implies this), then problems may arise. Because something from your module will crawl into the global scope of all modules that are connected within the application, where your module is also connected. A very risky move in my opinion.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question