How can I set NODE_ENV=production on Windows?

Jack picture Jack · Feb 12, 2012 · Viewed 385k times · Source

In Ubuntu it's quite simple; I can run the application using:

$ NODE_ENV=production node myapp/app.js

However, this doesn't work on Windows. Is there a configuration file where I can set the attribute?

Answer

Jani Hartikainen picture Jani Hartikainen · Feb 12, 2012

Current versions of Windows use Powershell as the default shell, so use:

$env:NODE_ENV="production"

Per @jsalonen's answer below. If you're in CMD (which is no longer maintained), use

set NODE_ENV=production

This should be executed in the command prompt where you intend to run your Node.js application.

The above line would set the environment variable NODE_ENV for the command prompt where you execute the command.

To set environment variables globally so they persist beyond just the single command prompt, you can find the tool from System in Control Panel (or by typing 'environment' into the search box in the start menu).