Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reload Express.js routes changes without manually restarting server

I tried express-livereload, but it just reloaded view files.

Should I use another tool, or this one can be configured to watch for my index.js file which runs the server?

I read that options are the same as node-livereload, and default for watched files include .js files.

Any URL you know with a simple configuration?

My main problem is how to setup good development environment for Express.js, and I would like to inspect the variables when I am making a request, is painful to restart each time I make a change in a route.

PS I tried node-inspector to inspect variables when server handles a request, but it seems node-inspector is not intended for that, right?

like image 373
sites Avatar asked Jul 15 '14 05:07

sites


People also ask

Which tool in Express js restart your server as soon as we make a change in any of your files otherwise we need to restart the server manually after each file modification?

nodemon restarts the server on any changed backend file.

How does routing work in Express js?

A route method is derived from one of the HTTP methods, and is attached to an instance of the express class. The following code is an example of routes that are defined for the GET and the POST methods to the root of the app. Express supports methods that correspond to all HTTP request methods: get , post , and so on.

How do you restart a Javascript server?

If it's just running (not a daemon) then just use Ctrl-C.

Is Express js unmaintained?

It is unmaintained Express has not been updated for years, and its next version has been in alpha for 6 years. People may think it is not updated because the API is stable and does not need change. The reality is: Express does not know how to handle async/await .


2 Answers

I think Nodemon has what you're looking for.

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

Example invocation:

nodemon index.js 
like image 112
stellarchariot Avatar answered Oct 05 '22 12:10

stellarchariot


I use express.js, normally start server by

npm start 

with Nodemon installed, I use

nodemon --exec npm start 

Note: nodemon app.js will NOT work here,

because express.js use start script

To install nodemon

npm install -g nodemon 
like image 38
hoogw Avatar answered Oct 05 '22 10:10

hoogw