Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js - nodemon vs node - development vs production

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?

like image 443
Alexander Mills Avatar asked Nov 08 '14 02:11

Alexander Mills


People also ask

Is Nodemon a production?

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.

What is a benefit of using Nodemon when developing node JS applications?

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.

Can I use Nodejs in production?

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.


2 Answers

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
like image 164
Daniel Avatar answered Oct 17 '22 02:10

Daniel


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.

like image 11
Remy Sharp Avatar answered Oct 17 '22 01:10

Remy Sharp