env-cmd icon indicating copy to clipboard operation
env-cmd copied to clipboard

how to set env var from CLI that overrides matching var in .env file?

Open noahehall opened this issue 4 years ago • 3 comments

I have a base .env file that I need to override without creating a gizillion other env files, or creating an envfile with superhuman capabilities

ive tried NODE_ENV=production env-cmd runpoop.js

however it doesnt replace the nodenev in the .env file

How do I do this? is it possible? here is the specific npm script im trying to run

noahehall avatar Jun 20 '21 16:06 noahehall

here is my workaround until i find a better approach

I had to rely on dotenv, as env-cmd.GetEnvFromVars thing returns a promise, and I cant use top-level await when outputing to cjs via esbuild (thus i cant use promises without other headaches)

Any guidance on this?

noahehall avatar Jun 21 '21 13:06 noahehall

Hi,

did you try --no-override option ?

regards,

fidgi avatar Jul 24 '21 10:07 fidgi

I just used the --no-override option as suggested by @fidgi and it worked like a charm.

Just make sure to set the variable(s) on the same shell you're executing env-cmd or as an environment variable:

  • shell variable: ABC=123 env-cmd --no-override ...
  • environment variable: export ABC=123 && env-cmd --no-override ...

ABC=123 && env-cmd --no-override ... won't work, as it sets ABC in one shell and runs env-cmd on another.

leite08 avatar Jan 15 '22 18:01 leite08