Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to reload the nodejs app after making changes to the file?

i have a simple js file with http module to test Hello node for nodejs....

below is the http_test.js file

var http = require('http');

http.createServer(function(req, res) {
    res.writeHead(200);
    res.end('hello node');
}).listen(8080);

node http_test.js prints fine on the browser...now if i change my response line to say res.end('changed hello node to hello stoner');, i still get previous hello node on my page....

to get the changed line i got to end the current instance of node and then again run node http_test.js

if i make any changes to js file should i restart over?

wouldnt just hitting refresh on my browser do it?

like image 603
coolstoner Avatar asked Sep 24 '16 12:09

coolstoner


1 Answers

1) Install nodemon. To install, from your terminal run:

npm install -g nodemon

2) Now, go to terminal, where you have the program. And, run

nodemon http_test.js

Now, everytime when you make changes to your app, just save your changes and it will get reflected.

Details :-

Nodemon is a utility that will monitor for any changes in your source and automatically restart your server. Perfect for development. Install it using npm.

Just use nodemon instead of node to run your code, and now your process will automatically restart when your code changes.

Please refer :-

http://nodemon.io/

https://github.com/remy/nodemon

like image 188
satyam kumar Avatar answered Nov 11 '22 05:11

satyam kumar