Live reload EJS file in browser

mail@pastecode.io avatar
unknown
javascript
a month ago
605 B
5
Indexable
Never
//Livereload/refresh any ejs render file in browser automatically
//Step:1>>In your Project folder enter this command>> npm i -D livereload connect-livereload
//Step:2 >> In app.js insert below code after declare and define app and port of expressjs

const livereload = require("livereload");
const connectLiveReload = require("connect-livereload");
const liveReloadServer = livereload.createServer();
liveReloadServer.watch(path.join(__dirname, "views"));
liveReloadServer.server.once("connection", () => {
	setTimeout(() => {
		liveReloadServer.refresh("/");
	}, 100);
});
app.use(connectLiveReload());
Leave a Comment