I would like to use $>npm start and have it use "nodemon" for development and "node" for production. I can't put conditional logic in my package.json file, so how is this best accomplished?
Node.js - nodemon vs node - development vs production
22.8k Views Asked by Alexander Mills At
4
There are 4 best solutions below
4
On
You should be able to use NPM's start as a regular shell script.
"scripts": {
"start": "if [$NODE_ENV == 'production']; then node app.js; else nodemon app.js; fi"
}
Now to start your server for production
$ NODE_ENV='production' npm start
or for development
$ NODE_ENV='development' npm start
nodemon actually reads the
package.startvalue, so if you just set thestartproperty to what you'd have in production, likenode app.js, then run nodemon without any arguments, it'll run withpackage.startand restart as you'd expect in development.