1 min readMay 31, 2021


Photo by Alex Chumak on Unsplash

If you need a more maintainable and secure code. the DotEnv package allows you to offset your environment variables more easily and simpler to use with Node.
DotEnv is a lightweight npm package that automatically loads environment variables from an .env file into the process.envobject.

How to Create a .env File

Create a file called .env at the top level of your file structure. This is where you will create all your environment variables, written in NAME = value format. like this: PORT = 5000.

How to Access the Environment Variables

The variables are attached to the process.env object, so you can access them using the process.env.KEY template.

To modify the value of one of your variables, all you have to do is modify the .env file.


You should not pass it on, as it may contain sensitive data such as authentication keys and passwords. Add the file to .gitignore to avoid accidentally uploading it to a public repository.





Recommended from Medium