GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||
GeezerVison is showing github.com — src: add built-in `.env` file support by anonrig · Pull Request #48890 · nodejs/node Conversation
|
|
Review requested:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I think we'll get a number of follow up requests beyond the most basic functionality. A few that I think we should have some plan for:
Note, some of these are taken directly from the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
regarding testing and validation, you can take dotenv's test suite (which afaik is the most popular package for parsing .env files): https://github.com/motdotla/dotenv/tree/master/tests my other concerns were already mentioned just before I was about to comment |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thank you for doing this! My vote is that the flag should be --env-file [path-to-file] so like --env-file .env or --env-file .env.development or whatever, so that people can have multiple files per environment like how Bun handles this. If we’re going to require a flag at all, we might as well make it versatile.
And a future PR can potentially add support for configuring Node without needing opt in via flag, like potentially a node.config.json file or a field in package.json; but those implementations can live alongside this one.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
I think it’s okay if we define our scope as more limited than That said, from your list I already mentioned allowing specifying the path to the file, and I think we need to at least document what we do for conflicts; I think the simplest approach is to just always have the “real” environment variable win out over whatever is defined in the file, and leave it at that. It would be nice to ignore lines starting with One other thing we should do is mark this as experimental in the docs. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
There is a question: how about .env.local .env.*.local …
there will have multiple different env file during the development
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Supporting incremental .env files would be great (e. .env.test with overrides over generic .env) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
See, the feature requests already start piling up... Apart from this being an infinitely slippery slope, I also feel it goes directly against node's "mechanism over policy" philosophy. Not a fan. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Please consider adding support for env expand. It's insane to think that dotenv-expand has 12 million weekly download which has no defined grammer. test$var the list goes on. Too much regex in Node community 🙂 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I think it can be implemented as a follow-up pull request, if anyone is interested in implementing. I'm in favor of keeping the implementation as small as possible (for now). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
97aacf7 to
5b5dcc9
Compare
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
e00e3e8 to
0541c35
Compare
There was an error while loading. Please reload this page.
|
What is this feature's interaction with the permission model? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
@panva If we want to support NODE_OPTIONS, it needs to bypass permission model, since V8 will not be initialized at that time. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
So an |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@nodejs/tsc This seems like the kind of thing the TSC should have an opinion on. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Amazing, thanks for this!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Landed in 769823e |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Thanks @anonrig! You've saved a few hundred thousand people (maybe more) a little work by including this! ❤️ |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| "[has_env_file_string]", "", &EnvironmentOptions::has_env_file_string); | ||
| AddOption("--env-file", | ||
| "set environment variables from supplied file", | ||
| &EnvironmentOptions::env_file); |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@anonrig Was it a deliberate decision to not set kAllowedInEnvvar for this option?
I'm asking, because in order to replace the dotenv-npm-package with the native dotenv-package (this feature) AND using npm scripts, I need to set NODE_OPTIONS='--env-file .env' in my .npmrc file.
Currently, this is not possible because kAllowedInEnvvar is not set.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It wasn't a deliberate decision. Prs are welcome :-)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Is there a risk of a loop here? Like what if an .env file contains NODE_OPTIONS='--env-file .env'?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
No there isn't
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the info! I'll read through the contribution guidelines and open a PR.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
it would be really useful when running node-scripts via npm
How so? What is a script you would use it for?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
How so? What is a script you would use it for?
In my case I'm running playwright via npm like this:
{
"name": "npm-package",
"scripts": {
"test:browser": "playwright test"
}
}Inside my playwright config, I'm currently using dotenv.config() to get the baseUrl for the current env.
import dotenv from 'dotenv'; dotenv.config(); const config: PlaywrightTestConfig = { baseURL: process.env.PLAYWRIGHT_BASE_URL, }; export default config;
I'd like to get rid of the npm dotenv-dependency and use the native Dotenv functionality, without having to change my npm scripts to something like node --env-file=.env node_modules/.bin/playwright test.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
without having to change my npm scripts to something like
node --env-file=.env node_modules/.bin/playwright test
So you're saying you prefer to do NODE_OPTIONS=--env-file=.env playwright test? Node doesn't automatically load .env files.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
So you're saying you prefer to do
NODE_OPTIONS=--env-file=.env playwright test? Node doesn't automatically load .env files.
Yes, sort of.
As far as i know, I can use .npmrc and node-options to automatically apply NODE_OPTIONS to called lifecycle scripts (like playwright).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
As far as i know, I can use
.npmrcandnode-optionsto automatically applyNODE_OPTIONSto called lifecycle scripts (like playwright).
Interesting, I didn’t know about node-options!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Which is the standard or recommended file pattern? Refer to https://nodejs.org/en/learn/command-line/how-to-read-environment-variables-from-nodejs |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
.foo.env is the preferred one |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
A further suggestion: We should treat |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.