DEV Community

Cover image for Using dotenv to manage environment variables in Nodejs

Using dotenv to manage environment variables in Nodejs

Hridayesh Sharma on April 27, 2020

Have you ever faced any of these scenarios: You have some dynamic values in your code which you don't want to hardcode. You have API K...
Collapse
 
joeattardi profile image
Joe Attardi

I use dotenv in all of my Node projects now!

Collapse
 
vyasriday profile image
Hridayesh Sharma

Yeah it's great!

Collapse
 
mgrachev profile image
Grachev Mikhail

Another useful tool — github.com/dotenv-linter/dotenv-li....
It’s a lightning-fast linter for .env files. Written in Rust.

Collapse
 
denid88 profile image
Denis

After read this article, i starting use dotenv, thanks

Collapse
 
vyasriday profile image
Hridayesh Sharma

Thanks denid. This is a great motivation for me. 😃

Collapse
 
christophecraig profile image
Christophe Craig

I just learned about dotenv a few days ago and started using it but now, with dotenv-flow that will really be great ! Thanks a lot for that

Collapse
 
vyasriday profile image
Hridayesh Sharma

Glad that this post helped you. :)

Collapse
 
vjnvisakh profile image
Visakh Vijayan

How to change env variables according to environment using dotenv

Collapse
 
vyasriday profile image
Hridayesh Sharma • Edited

You can use dotenv-flow for that. I have updated the post for the same.

Collapse
 
kiransiluveru profile image
kirankumar

How to Access the ENV var in different files in Node.js using dotenv?

Collapse
 
vyasriday profile image
Hridayesh Sharma

Hi Kiran You can access ENV variables like process.env.VARIABLE_NAME once you load dotenv in your file.