Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Watch command for Node.js HTTP Server

I am using express and every time I make a change to my controller, I need to restart the HTTP server, which is somewhat inconvenient. Is there a "watch" command or an equivalent in express or Node.js that watches for changes and restarts the server automatically?

like image 951
Ram G Athreya Avatar asked Oct 19 '13 16:10

Ram G Athreya


People also ask

Is NodeJS a HTTP server?

Node. js has a built-in module called HTTP, which allows Node. js to transfer data over the Hyper Text Transfer Protocol (HTTP). The HTTP module can create an HTTP server that listens to server ports and gives a response back to the client.

What is HTTP server in node JS?

Node.js has a built-in module called HTTP, which allows Node.js to transfer data over the Hyper Text Transfer Protocol (HTTP). To include the HTTP module, use the require() method: var http = require('http');


3 Answers

Try nodemon, it will restart your application every time you made a change

like image 96
Ratzo Avatar answered Oct 19 '22 12:10

Ratzo


To watch files for changes, you could use fs.watch() or fs.watchFile(). However, daemon modules such as supervisor or nodemon exist for your purpose.

like image 27
hexacyanide Avatar answered Oct 19 '22 13:10

hexacyanide


I use node-dev for automatic restart on source code change.

like image 7
Peter Lyons Avatar answered Oct 19 '22 13:10

Peter Lyons