coolstoner coolstoner - 2 months ago 14
Javascript Question

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?

Answer

You need to stop and re run the server to see your latest update. To automate this, you can use nodemon, do npm i nodemon -g

And run nodemon http_test.js

Now, for every change you make tohttp_test.js the server will be restarted automatically

Comments