process.env

process.env

An object containing the user environment. See environ(7).

An example of this object looks like:

{ 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' }

You can write to this object, but changes won't be reflected outside of your process. That means that the following won't work:

$ node -e 'process.env.foo = "bar"' && echo $foo

But this will:

process.env.foo = 'bar';
console.log(process.env.foo);

Assigning a property on process.env will implicitly convert the value to a string.

Example:

process.env.test = null;
console.log(process.env.test);
// => 'null'
process.env.test = undefined;
console.log(process.env.test);
// => 'undefined'

Use delete to delete a property from process.env.

Example:

process.env.TEST = 1;
delete process.env.TEST;
console.log(process.env.TEST);
// => undefined
doc_Nodejs
2016-04-30 04:41:12
Comments
Leave a Comment

Please login to continue.