-
-
Notifications
You must be signed in to change notification settings - Fork 861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NodeJS 18 native feature caveats and dotenvx
#774
Comments
TLDR: This is great to see from Node, but we don't recommend dropping dotenv just yet. The Node native feature is missing some key features at the moment. Node.js 20.6.0 includes built-in support for .env filesNode v20.6.0+ adds native support for loading
Wow, cool! Is dotenv dead? Stop using it? Not so fast. Don't drop dotenv just yet. There are some caveats you should know first. First, let me say, it is great to see the NodeJS team adopt first-class Anyways, let's see how this built-in support works (or skip to the caveats section). How it worksInstall Node v20.6.0 or greater using nvm.
Create your
Create your node script to make use of it.
Run it with the
That's it! Want to run it in production? Just point it to a
CaveatsThe biggest current caveat is that this is still an experimental feature. That means it will ship with bugs and with missing feature support. The top hn comment sums it up well - albeit a bit grumpily. I also want to stress the word current because this is all still under active development. These things take time. By the time you read this, some of these caveats might no longer be around. Missing multiline supportThe current implementation does not support multiline environment variables. If you attempt to include a multiline environment variable it will be
Note: multiline support is being actively discussed and will probably get added in the near future. Missing override optionYou cannot override your system's environment variables with your
It prints If you need to do this then continue using dotenv with its override option. Missing variable expansionVariable expansion support for dotenv exists in a separate library dotenv-expand. But it is so widely used with 13 million downloads weekly that it is defacto considered part of dotenv. As of this writing, Node does not support variable expansion. Instead, it will output the variable as a string.
So if you need variable expansion, you should continue using dotenv and dotenv-expand. Missing
|
@motdotla great comment! I wonder why Node team half bake features? Like with Fetch? Is it so hard to make them fully baked? |
it is nice to see them add it though and further development is underway. you can support development by sponsoring @anonrig https://github.com/sponsors/anonrig also, we are moving a lot of such effort into |
I'ld lke to add: missing env files will now cause the native env loader to throw an error, and that's intented. So seems like one should stick to to .dotenv. |
dotenvx
Seems like Node.js v20.12.0 just added Not 100% sure, but I think the caveats / missing features that @motdotla mentioned (multiline support, overrides, variable expansion) still apply: |
yes, still same caveats, but I think they will be working toward that over the next few months from the chatter I've seen. |
Is it true that the new version of nodes 18 or 20 I don't remember exactly provides natively this feature of reading the values from a .env file without any dependency?
The text was updated successfully, but these errors were encountered: