1.0.1 • Published 12 months ago

ejs-live-reload v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
12 months ago

ejs-live-reload

NPM Version

A Node.js module that automatically reloads the browser when EJS file content changes.

Installation

npm install ejs-live-reload

Usage

const express = require('express');
const ejsLiveReload = require('ejs-live-reload');

const app = express();
const server = require('http').createServer(app);

// Set up EJS
app.set('view engine', 'ejs');

// Use ejs-live-reload
ejsLiveReload(server, __dirname + '/views');

// Your routes and other middleware
app.get('/', (req, res) => {
  res.render('index');
});

server.listen(3000, () => {
  console.log('Server is running on port 3000');
});

Make sure to pass the server object (not the Express app) to the ejsLiveReload function.

How it works

This module uses chokidar to watch for changes in your EJS files and socket.io to communicate with the browser. When an EJS file is modified, it sends a message to the browser to trigger a reload.

1.0.1

12 months ago

1.0.0

12 months ago