Node.js v20 has been released and quite a few new features were included. Among those and included in version 20.6.0, there is the --env-file
flag, allowing you to import files for configuring environment variables natively. This is a popular feature among applications because dotenv
has amassed the staggering number of 36 millions weekly downloads.
As an avid dotenv user I wanted to thank their maintainers for keeping the project alive for 10 years (wow). A perfect exemplary of dedication to Open Source.
Going back to the --env-file
feature in hand, it can also be used to move NODE_OPTIONS
environment variable to your .env file and avoid clutter on your Node.js commands. Last but not least, have in mind that you will still be able to pass environment variables on the Node.js command and that they will take precedence over your .env file:
$ SECRET=123 node --env-file=.env -e "console.log(process.env.SECRET)"
The previous command will always print "123", no matter the value for the variable SECRET you define in your .env.
Top comments (0)