Software Development

Access environment variable in Node.js

[wp_ad_camp_1]

This short post shows how to access environment variables in Node.js.

Process object

Node.js has a global object process that can readily be used in your JavaScript application without explicitly using require.

Environment Variable

With the process  object, the env property can be used to access an environment variable. For example,

This will display the content of PATH.

[wp_ad_camp_2]

Example Usage

Let’s try creating a custom environment variable named MY_ENV_TEST with value of “This is my env variable”.

In your terminal (Windows), create the variable.

In the same terminal, run the following JavaScript.

[wp_ad_camp_3]

 

 

 

 

 

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like