How to read environment variables in Node js

0 votes
Is there a way to read environment variables in Node.js code?

Like for example Python's os.environ['HOME'].
Jul 8, 2020 in Node-js by kartik
• 37,510 points
1,360 views

1 answer to this question.

0 votes

Hello @kartik,

Yes,you can read environment variables in Node.js code as:

process.env.ENV_VARIABLE

Where ENV_VARIABLE is the name of the variable you wish to access.

For example:

var mode   = process.env.NODE_ENV;
var apiKey = process.env.apiKey; 

Hope it helps!!

Thank You!!

answered Jul 8, 2020 by Niroj
• 82,880 points

Related Questions In Node-js

0 votes
1 answer

How to write files in Node.js?

Hello @kartik, Currently there are three ways to ...READ MORE

answered Jul 8, 2020 in Node-js by Niroj
• 82,880 points
682 views
–1 vote
1 answer

How to uninstall npm modules in node js?

Hello @kartik, The command is simply: npm uninstall ...READ MORE

answered Jul 8, 2020 in Node-js by Niroj
• 82,880 points
2,809 views
0 votes
1 answer

How to process POST data in Node.js?

Hello @kartik, You can use the querystring module: var qs = ...READ MORE

answered Jul 9, 2020 in Node-js by Niroj
• 82,880 points
2,316 views
0 votes
1 answer

How to print a stack trace in Node.js?

Hello @kartik, To print stacktrace of Error in console in ...READ MORE

answered Jul 9, 2020 in Node-js by Niroj
• 82,880 points
590 views
0 votes
1 answer
0 votes
0 answers

Anyone can help me out to understand the semantic of (document.getElementBYId("demo").innerHTML="Hello") ?

Hello guys, Can Someone helps me to find ...READ MORE

Jan 17, 2020 in Web Development by anonymous
• 37,510 points
740 views
+1 vote
1 answer

What is the relationship between angularjs Scope with controller/view?

Let us consider the below block: <div ng-controller="emp"> ...READ MORE

answered Jan 20, 2020 in Web Development by Niroj
• 82,880 points

edited Jan 21, 2020 by Niroj 781 views
0 votes
1 answer

What are the vulnerability related to PHP Form?

Hii, The $_SERVER["PHP_SELF"] variable can be used by ...READ MORE

answered Feb 13, 2020 in PHP by Niroj
• 82,880 points
2,691 views
0 votes
1 answer

How to get GET (query string) variables in Express.js on Node.js?

Hello @kartik, Since you've mentioned Express.js in your ...READ MORE

answered Jul 8, 2020 in Node-js by Niroj
• 82,880 points
2,971 views
0 votes
1 answer

How to read binary files byte by byte in Node.js?

Hello, Here is an example of fs.read()-ing the first ...READ MORE

answered Nov 27, 2020 in Node-js by Niroj
• 82,880 points
12,272 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP