Is it possible to restart the NodeJS server when a modification occurs automatically?

4

Every time I try to do some modification in my app.js file I have to close and start the server for the modifications to take effect, would I have some way to restart automatically after a change? like in php.

Example:

var http = require('http');

var server = http.createServer(function(request, response){
    response.writeHead(200, {"Content-Type": "text/html"});
    response.write("<h1>Hello World!</h1>"); // <-- se mudar o texto no F5 não atualiza.
    response.end();
});

var servidorLigou = function () {
    console.log('Servidor Hello World rodando!');
};

server.listen(3000,servidorLigou);
    
asked by anonymous 12.07.2016 / 21:01

1 answer

3

You can use a supervisor for this role. An alternative to this role is nodemon .

To install is very simple, as the site shows:

$ npm install nodemon -g
$ nodemon app.js

This question has several options for supervisors and how to use it if you are interested.     

12.07.2016 / 21:19