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

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.

Leave a Comment