Ad

Node Process.env Setup Not Working On Npm Config Library

I am using 'config' library from npm.

I have folder like this

1.config/development.json (my development config)

2.config/production.json (my production config)

I am using nodemon and my package.json looks like below:

{
  "name": "superapp",
  "version": "1.0.0",
  "description": "A SuperAppSoftware",
  "main": "server.js",
  "scripts": {
    "test": "mocha",

    "dev": "concurrently \"npm run server-dev\" \"npm run client-dev\"",
    "client-dev": "webpack-dev-server",
    "server-dev": "set NODE_ENV=development&& nodemon server/server.js",

    "prod": "concurrently \"npm run server-prod\" \"npm run client-prod\"",
    "client-prod": "webpack-dev-server --hot --inline  --host 0.0.0.0 --port 3000",
    "server-prod": "set NODE_ENV=production&& nodemon server/server.js",

    "build": "webpack"
  },
}

In this package.json i am setting set NODE_ENV but the if i start npm run prod still the development.json inside config file working, but not production.json working.

Ad

Answer

In your package.json use:

"server-dev": "NODE_ENV=development nodemon server/server.js"

and

"server-prod": "NODE_ENV=production nodemon server/server.js"
Ad
source: stackoverflow.com
Ad