Languages
[Edit]
EN

cmd.exe - pass environment variables to Node.js process (during command running)

7 points
Created by:
Cassia
1265

In this article, we would like to show you how to pass environment variables to Node.js process using Windows Command Prompt (cmd.exe).

Quick solution (run in cmd.exe):

Where:

  • VARIABLE_NAME is environment variable name that we want to pass,
  • VARIABLE_VALUE is environment variable value that we want to pass,
  • script.js is file name that will be executed receiving the environment variable.

 

Warning: each character placed before && will be treat as variable value, so avoid unnecessary spaces.

Note: to escape & and ^ characters in variable value use ^ character, e.g.:

 

Practical example

Edit

In this example, we pass ADMIN_USERNAME and ADMIN_PASSWORD environment variables into script.js script. Then we access passed variables inside script.js script using process.env property.

script.js file:

cmd.exe command:

Script output:

 

See also

Edit
  1. Node.js - common way to pass environment variables to Node.js process (during command running)

  2. Bash - pass environment variables to Node.js process (during command running)

References

Edit
  1. Process | Node.js v19.1.0 Documentation

Alternative titles

  1. Command Prompt - pass env variables to Node.js process (during command running)
  2. Windows Command Prompt - pass env variables to Node.js process (during command running)
  3. cmd.exe - pass env variables to Node.js process (during command running)
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join