Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
63 views
in Technique[技术] by (71.8m points)

javascript - Environment Variables set using Batch can't be found in node.js script

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...