1

I'm trying to export environment variables to the calling shell/terminal/cmd in a platform agnostic way using node.

Is this possible?

Of course I can set variables using

FOO="bar"
echo $FOO

The following doesn't work but essentially I am hoping to do the same thing from node:

node -e "process.env.FOO = 'bar'"
echo $FOO 

Or perhaps using spawn or similar?

David Alsh
  • 6,747
  • 6
  • 34
  • 60
  • Are you looking to modify the environment as the current node process sees it or the environment used by the shell that's running that node process? The former is pretty simple, but the latter I have no clue about. – l3l_aze Sep 08 '20 at 04:45
  • The environment used by the shell that's running that node process - so the next program has access to the variables as set by the node script – David Alsh Sep 08 '20 at 22:53
  • According to the answers in [this question](https://stackoverflow.com/q/496702/7665043) that's not easily possible, but they do suggest some hack-y ways to do so that may work. Also seems to be a duplicate of this question, at their core. – l3l_aze Sep 09 '20 at 05:08

0 Answers0