coolstoner coolstoner - 6 months ago 37
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

var http = require('http');

http.createServer(function(req, res) {
res.end('hello node');

node http_test.js
prints fine on the 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?


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