Node.js Accessing environment variables


Example

The process.env property returns an object containing the user environment.

It returns an object like this one :

{
  TERM: 'xterm-256color',
  SHELL: '/usr/local/bin/bash',
  USER: 'maciej',
  PATH: '~/.bin/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin',
  PWD: '/Users/maciej',
  EDITOR: 'vim',
  SHLVL: '1',
  HOME: '/Users/maciej',
  LOGNAME: 'maciej',
  _: '/usr/local/bin/node'
}
process.env.HOME // '/Users/maciej'

If you set environment variable FOO to foobar, it will be accessible with:

process.env.FOO // 'foobar'