News for hackers. Stuff that matters.
Re:Node.js 20.6.0 will include built-in support for .env files by koolba on Friday August 18, 2023 @09:44AM (#37175525)
> Curious what features you use beyond this.

There’s plenty of outstanding questions.

Is the export required?

Can variables reference other variables?

Can variables reference existing variables in the environment?

Can you use other forms of expressions?

Can you set overridable defaults for values?

Re:Node.js 20.6.0 will include built-in support for .env files by sonthonax on Friday August 18, 2023 @10:26AM (#37176081)
It's a shell script that should be executable by any UNIX shell. Parsing it (rather than executing it) is why those questions are raised.
Re:Node.js 20.6.0 will include built-in support for .env files by claytongulick on Friday August 18, 2023 @10:45AM (#37176368)
In the nodejs community it's normally used via dotenv.

So, yes it's parsed and a valid use case.

Re:Node.js 20.6.0 will include built-in support for .env files by sergiotapia on Friday August 18, 2023 @12:57PM (#37178532)
I've never used/needed those features from my .env files that's why I'm asking for use cases. Are you saying you use those kinds of features in python_dotenv? I'm asking btw, no snark.
Re:Node.js 20.6.0 will include built-in support for .env files by SOLAR_FIELDS on Sunday August 20, 2023 @12:20AM (#37196101)
I use them in python_dotenv for declaring environments that I use to provision infrastructure, as an example:

Example, where we have:

env_type="dev"

env_name="myappenv"

primary_subnet_pod="${env_type}-${env_name}-gke-pod-subnet"

primary_subnet_service="${env_type}-${env_name}-gke-service-subnet"

Which I then might want to use further down, override with defaults, etc and so forth. It strikes a decent balance in that it's a bit more powerful than a static .env file, but doesn't require you to go full-on templating language with Jinja and the like. It's also cross-platform enough in that you could throw a .env in somewhere and expect most languages to have a client library to parse and load it into env.

If your use-case is right in that sweet spot it's a pretty good tool. But the behavior, as noted, isn't specced so I can't trust go_dotenv or rust_dotenv or whatever other library to treat it the same way.

Interestingly, in practice, it seems like the Node lib is the canonical version that inspired these other ones so in a way it serves as some sort of unofficial spec. It's not something I would write production grade code trusting the unofficial spec on though.