toddbluhm / env-cmd

Setting environment variables from a file
https://www.npmjs.com/package/env-cmd
MIT License
1.74k stars 65 forks source link

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

Open noahehall opened 3 years ago

noahehall commented 3 years ago

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 commented 3 years ago

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?

fidgi commented 3 years ago

Hi,

did you try --no-override option ?

regards,

leite08 commented 2 years ago

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:

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