Is it a good idea to add properties to Node's global
object? Searches for this lead me to a discussion of global variables in Node, and frankly I can't find much about the global
object for some reason.
From my understanding, global
in Node is analogous to the window
object that's used in the conventional JS environment, and mutating that is generally frowned upon.
I ask because I'm using Electron whose docs list all sorts of examples that use global
, and they even provide an API that lets us set/get global properties from other processes.
From a recent code review, my team was asked to replace the use of global
with our own Node module so to avoid overwriting important global attributes set by Node/Electron/3rd party resources.
This seems like a good idea, but why then does Electron recommend the use of global
? Why is that the paradigm?
Taking a closer look at the examples, it looks like they recommend only adding one property to the global (sharedObject
), so this isn't as bad as I thought, but is this good enough, or should I really take the time to create a separate Node module?
Perhaps this is an opinion-based question.