DotEnv has been an amazing library that I’ve used for years. Node.js v20.6.0
is finally release and include support .env
files
We now have built-in support for the .env
file. This mean that you can finally stop using the dotenv
package to load environment variables from .env
file. The authors of dotenv
package is archived his Github repository.
Setting up
Suppose you have a simple Express application
Now, create a file that had been named .env
at the root of the application next to app.js
file to store the environment variables.
By default, the Node.Js will be used file .env
to store environment variables. We can change the file name for our application by using the argument env-file
in start command. Example:
Need to change app.js
to check .env
is working correctly
Then now if you visit http://localhost:3000
you should see the text : “Hello, My name is Nam Hoai Nguyen”
dotenv
v15 support