How is setting an environment variable like process.env.thing = 42
different from creating a global variable like global.thing = 42
?
When would prefer process.env.thing
over global
? What are the pros/cons of both objects?
global
is the global object. process
is available globally, because it is a property of global
. In fact:
global.process === process //-> true
process.env
has properties set to the environment variables of the system. These can be set a variety of ways outside of node itself, and read in by accessing properties of process.env
.
At the command line try:
FOO=bar node -e "process.env.FOO"
The process module is just a globally available thing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With