I have a batch-file where various environment variables are being set like this:
SET foo=xyz
Those variables will be used in a later called node.js-script using
process.env.foo
.
Unfortunately, when trying to get the variable's value I get undefined.
When echoing the variable yet inside the batch-script using
@echo %foo%
the value will be printed out correctly.
I first start a new PowerShell window, then start the batch-script and finally start the node.js script using npm start. Thus both scripts are in the same session.
Do you have any ideas about what I might have overlooked?
EDIT:
I was actually not aware that PowerShell does not process the batch file in the same session as the node script. After trying to do the same steps, but in the command prompt, everything worked as expected.
Thank you all!
question from:
https://stackoverflow.com/questions/65625943/environment-variables-set-using-batch-cant-be-found-in-node-js-script 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…