javascript tutorial - [Solved-3 Solutions] Read environment variables in Node.js - javascript - java script - javascript array



Problem:

How to read environment variables in Node.js?

Solution 1:

process.env.ENV_VARIABLE
click below button to copy the code. By JavaScript tutorial team

Where ENV_VARIABLE is the name of the variable

Solution 2:

  • using Node.js , you can retrieve environment variables by key from the process.env object:
  • for example
var mode   = process.env.NODE_ENV;
var apiKey = process.env.apiKey; // '42348901293989849243'
click below button to copy the code. By JavaScript tutorial team

Solution 3:

want to use a string key generated in your Node.js program, say, var v = 'HOME', we can use process.env[v] . Otherwise, process.env.VARNAME has to be hardcoded


Related Searches to javascript tutorial - Read environment variables in Node.js