Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add live-reload to my nodejs server

This is how can i run my server nodejs. I need to live reload my server when i make changes to the code in the front-end dev

"start": "node server.js" 
like image 888
Rebai Ahmed Avatar asked Aug 10 '17 19:08

Rebai Ahmed


People also ask

How do I reload node server?

Live Reload Frontend along with node server: To do this we are going to use livereload package. Fire up the terminal and run npm install livereload. Now inside your main server file In my case I have server. js Inside this file, we have to require livereload package and then reload(your_server_var); function.

Does Nodemon reload hot?

Use nodemon for hot reloading Nodemon monitors for any changes in your source code and automatically restarts your application.

How do I restart node JS?

While Nodemon is running, we can manually restart our application. So instead of stopping and restarting Nodemon, we can just type rs and press enter, and Nodemon will restart the server or the running process for us.


1 Answers

first:

npm install -g nodemon 

next add a script line to your package.json

"live": "nodemon server.js"  

now when you npm live it'll live reload

for more details see https://github.com/remy/nodemon

update if live page reload is also needed

npm install -g livereload livereload . -w 1000 -d 

for more details see https://github.com/napcs/node-livereload

like image 91
Mark Essel Avatar answered Sep 29 '22 12:09

Mark Essel