Devin McQueeney
Devin McQueeney

Reputation: 1287

How do I modify the Node.js package.json file depending on the environment i'm in?

I'd like to change the start script in package.json depending on the environment i'm in:

e.g, i'd like this in development:

"scripts": {
  "start": "node app.js"
},

...and this in production:

"scripts": {
   "start": "forever -a start ./server.js"
},

Is it possible for package.json to read environment variables? Then I could just throw that string into one of those...

Thanks!

Upvotes: 0

Views: 388

Answers (1)

Carlo
Carlo

Reputation: 2112

What about using an environment variable ?

Something like:

"scripts": {
   "start": "if [ -z "$ENV_PROD" ]; then forever -a start ./server.js; else node app.js; fi"
},

Upvotes: 1

Related Questions