I need to set some environment variables from within a script.
Those variables must:
- be visible to other processes in the same shell (not just child processes created by this node process)
- outlive the node process that set the variables
It is not good enough to manipulate process.env. I've seen a couple of SO questions that sound identical to mine, but both of them accepted answers to the effect of "assign values to process.env[your_var]", which fails both of my criteria.
I was using a little sugar on top of execa, to do (basically) this:
await execa( `export MY_VAR=osmethne` )
But that blows up:
Error: Command failed with exit code 2 (ENOENT): export MY_VAR=osmethne
spawn export ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
at onErrorNT (internal/child_process.js:415:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
error Command failed with exit code 1.
This all happens in Dockerized linux. So, I don't need to support Windows or OS/2 Warp or any other nonsense.