Home > database >  How to use live reload in an express server
How to use live reload in an express server

Time:05-19

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?

CodePudding user response:

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

  • Related