Skip to content

Instantly share code, notes, and snippets.

@hugmanrique
Last active June 30, 2018 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hugmanrique/8e71844cf20f5f49ff856137b723a7ae to your computer and use it in GitHub Desktop.
Save hugmanrique/8e71844cf20f5f49ff856137b723a7ae to your computer and use it in GitHub Desktop.
How to setup the NODE_ENV variable

NODE_ENV works like any other environment variable (e.g. PATH) and it depends on your platform how to set it:

  • Linux and OSX use the simple format NODE_ENV=production
  • Windows uses the SET NODE_ENV=production

You can explicitly set it before starting your npm run script by prepending the previous format:

package.json

{
  "scripts": {
    "build": "NODE_ENV=production webpack"
  }
}

cross-env makes it so you can have a single command without worrying about setting or using the environment variable properly for the platform. Just set it like you would if it's running on a POSIX system, and cross-env will take care of setting it properly:

First, run npm i -D cross-env, next change your npm run script:

{
  "scripts": {
    "build": "cross-env NODE_ENV=production webpack"
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment