title: npm: How to set NODE_ENV in Windows (10)?
body: <p>I am trying to add an npm script in package.json that sets <code>NODE_ENV</code> before doing something else (like running webpack). But although the syntax seems to be correct, <code>NODE_ENV</code> is not set when running under Windows 10.</p>
  
  <p>Test script</p>
  
  <pre><code>"scripts": {
     "test": "SET NODE_ENV=debug &amp;&amp; echo %NODE_ENV%" }
  </code></pre>
  
  <p>The result from <code>npm run test</code> is "production" (provided <code>NODE_ENV</code> was set to "production" before running the script). Should be "debug".</p>
  
  <p>What could be wrong? I even tried <a href="https://www.npmjs.com/package/cross-env" rel="nofollow noreferrer">cross-env</a> with no success.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>To clarify my question: I cannot set <em>any</em> environment variable under Windows 10. And I need to call SET because I am running the script under Windows (10). Seems to be some rights problem (scripts not allowed to set environment variables?).</p>
  
  <p>Another (or the actual) question would be: How can I create one script to build (using webpack) with creating minified versions of JavaScript files (for production), and one script to create non-minified versions (for development). So far I use following approach (see comments for the important parts):</p>
  
  <p><strong>Edit 2</strong></p>
  
  <p>I did not now that this probably made a difference, but in case it does: I worked with an React app created with create-react-app. I found the answer to my question, see below.</p>
  
  <p><strong>package.json:</strong></p>
  
  <pre><code>{
    "name": "test",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
  
      // Scipts for build for development and for production
      "build-dev": "SET NODE_ENV=debug webpack",
      "build-release": "SET NODE_ENV=production webpack"
  
    },
    "author": "",
    "license": "ISC",
    "dependencies": {
      "babel-core": "^6.24.1",
      "babel-loader": "^7.0.0",
      "babel-preset-env": "^1.4.0",
      "babel-preset-react": "^6.24.1",
      "debug": "^2.6.4",
      "webpack": "^2.4.1"
    }
  }
  </code></pre>
  
  <p><strong>webpack.config.js:</strong></p>
  
  <pre><code>const path = require('path');
  var webpack = require('webpack');
  
  // Check if in debug environment
  var debug = process.env.NODE_ENV !== "production";
  
  module.exports = {
    context: path.join(__dirname, 'src'),
    entry: ['./index.js'],
    output: {
      path: path.join(__dirname, 'www/js'),
      filename: 'index.js',
    },
    devtool: 'source-map',
    module: {
      rules: [
        {
          test: /\.jsx?$/,
          exclude: /node_modules/,
          use: ['babel-loader'],
        }],
    },
  
    // Add the UglifyJs plugin only in debug mode
    plugins: debug ? []  : [new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false })],
  
    resolve: {
      modules: [
        path.join(__dirname, 'node_modules')
      ]
    }
  };
  </code></pre>
  
  <p>This fails because setting NODE_ENV does not work for some reason. Using the command prompt directly like in the scripts:</p>
  
  <pre><code>SET NODE_ENV = debug
  webpack
  </code></pre>
  
  <p>works by the way. That's proof that the configuration is okay, but just the npm script cannot set NODE_ENV.</p>