node-env-run
node-env-run copied to clipboard
Support load .env into the current shell
I want to load .env
into the current shell environment, does it support this feature?
It sort of is. It's technically not the current shell environment but you could spawn a new shell using the tool. For example
npx node-env-run -e bash
This will open bash inside your current shell with the new environment variables applied. Similarly you could replace bash
with whatever shell you want to run or even run:
npx node-env-run -e $SHELL
This would run a new shell with whatever you are already as your current shell.
Note This will spawn a new shell inside your shell. So it will look like you just successfully executed a command but in reality you are inside a shell inside your shell. Meaning once you are done with your work you should consider running exit
to get out of the nested shell.
Also if you just want to load in the .env
file itself you can consider using source .env
instead. This should just load them in.
You are right, I find it it difficult to change environment variables of parent process from the child process. The quick method for this maybe create a sub shell process.
Also source .env
only works in Unix/Linux, does not work in Windows cmd
or powershell
.
https://unix.stackexchange.com/questions/372627/is-it-possible-to-pass-environment-variables-from-child-to-parent-in-user-space