Node.js: Is there any documentation about the process.env variable

I use process.env little in my program, it seems that this variable has nothing to do with my program, without it my application can work well too.

So how can I fully use process.env ? Is there any document or textbook in it?

+59
process
Feb 25 '13 at 1:52
source share
2 answers

Try this link http://nodejs.org/api/process.html#process_process_env

Then you can make a small program in nodeJS:

 console.log(process.env) 

And run it

 $ node myProgram.js { TERM_PROGRAM: 'iTerm.app', TERM: 'xterm', SHELL: '/bin/bash', CLICOLOR: '1', TMPDIR: '/var/folders/ff/59np25p96x95hpgbtsv3r6zr0000gn/T/', Apple_PubSub_Socket_Render: '/tmp/launch-LIiu0r/Render', OLDPWD: '/Users/hermanjunge', USER: 'hermanjunge', COMMAND_MODE: 'unix2003', SSH_AUTH_SOCK: '/tmp/launch-XOMy7j/Listeners', __CF_USER_TEXT_ENCODING: '0x1F5:0:0', Apple_Ubiquity_Message: '/tmp/launch-jiZQH0/Apple_Ubiquity_Message', LSCOLORS: 'ExFxCxDxBxegedabagacad', PATH: '/Users/hermanjunge/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin:/usr/local/mysql/bin', PWD: '/tmp', ITERM_PROFILE: 'hermanjunge', SHLVL: '1', COLORFGBG: '7;0', HOME: '/Users/hermanjunge', ITERM_SESSION_ID: 'w1t4p0', LOGNAME: 'hermanjunge', LC_CTYPE: 'UTF-8', DISPLAY: '/tmp/launch-HCtQeC/org.macosforge.xquartz:0', _: '/usr/local/bin/node' } 

Then we learned that we can get elements from the environment in which we run our application. For example, for example:

 console.log(process.env.PWD); 

What returns

 /tmp 

And so on...

+79
Feb 25 '13 at 1:59
source share

There is no documentation for process.env variables as it is based on your environment. (Surprise).

When the operating system (OS, Linux, Win or another) starts the process, it passes to it the environment variables that the process can read.

Using process.env , you can read the variables passed to your programs by the operating system.

Typically, NodeJS projects use process.env for two things:

  1. Things that need to be changed between environments. For example, development, testing and production. You do not want to connect to a real database during development and do not want to show all console.log in production.
  2. Keeping a Secret It is unsafe to keep APIs, tokens, and private keys on Git. Thus, you save the settings using an environment variable before starting the application.

Advice from a professional: there is another way. To define things in the .env file. To this file in your .gitignore , and use the npm dotenv module

+1
Sep 08 '19 at 7:57
source share



All Articles