Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass Node.js environment variable with Windows PowerShell [duplicate]

Tags:

I'm trying pass an environment variable to Node.js with PowerShell like this way:

C:\Users\everton\my-project> $env:MY_VAR = 8000 node index.js 

But I get an error in PowerShell:

Token 'node' unexpected expression or statement

like image 349
Everton Santos Avatar asked Mar 26 '17 04:03

Everton Santos


1 Answers

Set environmental variable MY_VAR first and run your app like this:

C:\Users\everton\my-project> $env:MY_VAR="8000" ; node index.js 

You can access environmental variable MY_VAR inside index.js by

process.env.MY_VAR 

Note: PowerShell doesn't directly support command-scoped environment variables. The above command sets the environment variable for that PowerShell session.

like image 174
Harikrishnan Avatar answered Oct 08 '22 02:10

Harikrishnan