Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reflect html changes in browser without restarting the express app

I have an express app. I am using swig as the template engine. Is it possible to reflect my HTML changes in the browser when I click refresh. I don't want to restart the server every time I need to do a HTML change?

like image 432
Akhi Avatar asked Dec 20 '12 07:12

Akhi


People also ask

How can we render plain HTML in Express?

We can render them directly into our server by specifying the response to send when the default route is accessed. const express = require("express"); const app = express(); app. listen(3000, () => { console. log("Application started and Listening on port 3000"); }); app.

What is Nodemon used for?

nodemon is a tool that helps develop Node. js based applications by automatically restarting the node application when file changes in the directory are detected. nodemon does not require any additional changes to your code or method of development. nodemon is a replacement wrapper for node .

How do you refresh Nodemon?

Add Start Script in pacakge. It's time to check how does nodemon is working in our app, open the terminal and start the app using the following command: nodemon server. js # [nodemon] 1.19. 1 # [nodemon] to restart at any time, enter `rs` # [nodemon] watching: *.


3 Answers

I got the solution from this link.

I installed supervisor module as global installation

npm install supervisor -g

I stated my app like this

supervisor -e html,js  app.js

Here i am specifying to watch the changes in files with extensions .html and .js. So when these files are changed its automatically reloaded when the next request comes.No restart required.

like image 186
Akhi Avatar answered Sep 28 '22 16:09

Akhi


There are plenty of tools for this:

  • nodemon
  • supervisor
  • node-hot-reload

And I'm sure you could find more.

like image 35
Florian Margaine Avatar answered Sep 28 '22 16:09

Florian Margaine


You can simply disable swig's caching:

if (process.env.NODE_ENV !== 'production') {
  swig.setDefaults({ cache: false });
}
like image 32
Domi Avatar answered Sep 28 '22 18:09

Domi