LEARNNode CLI Automation

Node Process env

There is another very useful property of Node.js process object. It's called process.env. Let's take a look at it now.


When you write this expression and save it in some variable, you will get all the information about your environment in an object. 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 also set some custom key/value pairs here which you don't want to commit to GitHub. For instance, if I want to save my API key, I can just do the following and it will be saved in my environment object:

process.env.API = "API_KEY"

Wrapping Up

This environment variable is quite useful and you can store all of the important information here like your database password, your username, etc. Go ahead and try it out!

Posted by Saad (It's a work in progress: Needs copy editing review by Awais.)