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?
Short answer: You don't require nodemon in production. nodemon is a tool that helps develop node. js based applications by automatically restarting the node application when file changes in the directory are detected.
Advantages of Using nodemon Module:It is easy to use and easy to get started. It does not affect the original code and no instance require to call it. It help to reduce the time of typing the default syntax node <file name> for execution again and again.
The platform runs on Linux, MacOS, FreeBSD, and Windows. Node. js applications can be run at the command line, but we'll focus on running them as a service, so that they will automatically restart on reboot or failure, and can safely be used in a production environment.
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.start
value, so if you just set the start
property to what you'd have in production, like node app.js
, then run nodemon without any arguments, it'll run with package.start
and restart as you'd expect in development.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With