Running non-Node code While Nodemon is running, we can manually restart our application. So instead of stopping and restarting Nodemon, we can just type rs and press enter, and Nodemon will restart the server or the running process for us.
You can restart the process at any time by typing rs and hitting ENTER . Once you make the changes to package. json , you can then call nodemon to start the example app in watch mode without having to pass in server.
During the Node. js development process, developers are required to make several changes in the running code. To make the updates take effect, the Node. js server needs to be restarted repeatedly.
A good option is Node-supervisor:
npm install supervisor -g
and after migrating to the root of your application use the following
supervisor app.js
You should look at something like nodemon.
Nodemon will watch the files in the directory in which nodemon was started, and if they change, it will automatically restart your node application.
Example:
nodemon ./server.js localhost 8080
or simply
nodemon server
forever module has a concept of multiple node.js servers, and can start, restart, stop and list currently running servers. It can also watch for changing files and restart node as needed.
Install it if you don't have it already:
npm install forever -g
After installing it, call the forever
command: use the -w
flag to watch file for changes:
forever -w ./my-script.js
In addition, you can watch directory and ignore patterns:
forever --watch --watchDirectory ./path/to/dir --watchIgnore *.log ./start/file
Various NPM packages are available to make this task easy.
For Development
For Production (with extended functionality such as clustering, remote deploy etc.)
npm install -g pm2
npm install -g strongloop
Comparison between Forever, pm2 and StrongLoop can be found on StrongLoop's website.
You can also try nodemon
To Install Nodemon
npm install -g nodemon
To use Nodemon
Normally we start node program like:
node server.js
But here you have to do like:
nodemon server.js
node-dev
node-dev is great alternative to both nodemon and supervisor for developers who like to get growl (or libnotify) notifications on their desktop whenever the server restarts or when there is an error or change occur in file.
Installation:
npm install -g node-dev
Use node-dev, instead of node:
node-dev app.js
Notification on Changing file so server start automatically
console out put
I use runjs
like:
runjs example.js
The package is called just run
npm install -g run
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