How to use live reload in an express server

Issue

So i’m using express to make a server:

const express = require('express');
const app = express();

const PORT = 3000;

app.use(express.static("public"));
app.get('/', (req, res) => {
    res.sendFile('index.html');
});

app.listen(PORT, () => {
    console.log(`Server running on http://localhost:${PORT}`)
});

The server works successfully, however i need it to live-reload when I update the HTML file

Can anyone help?

Solution

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

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

Answered By – MarcoWriteCode

Answer Checked By – Cary Denson (AngularFixing Admin)

Leave a Reply

Your email address will not be published.