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
2
On
I liked Daniel's solution, but thought it would be even cleaner to put it in a separate file, startup.sh:
#!/bin/sh
if [ "$NODE_ENV" = "production" ]; then
node src/index.js;
else
nodemon src/index.js;
fi
Then just change package.json to read:
"scripts": {
"start": "../startup.sh"
},
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.