automatically reload the browser for template and public asset changes in an express app
$ npm install @wajeht/express-templates-reload --save-dev
import express from 'express';
import { expressTemplatesReload } from '@wajeht/express-templates-reload';
const app = express();
// Must be placed before any other routes
expressTemplatesReload({
app,
watch: [
// Watch a specific file
{ path: './public/style.css' },
{ path: './public/script.js' },
// Watch a directory with specific extensions
{
path: './views',
extensions: ['.ejs', '.html'],
},
],
// Optional
options: {
pollInterval: 100, // Check for changes every 100ms (default: 50ms)
quiet: true, // Suppress console logs
},
});
app.get('/', (req, res) => res.send('Hello, world!'));
app.listen(80, () => console.log('App is listening on http://localhost'));
Parameter | Type | Description |
---|---|---|
app |
Application |
Express application instance |
watch |
Array |
Array of paths to watch |
watch[].path |
string |
File or directory path to watch |
watch[].extensions |
string[] |
File extensions to watch (required for directories) |
options.pollInterval |
number |
Polling interval in milliseconds (default: 50) |
options.quiet |
boolean |
Suppress console logs (default: false) |
- See DEVELOPMENT for
development
guide. - See CONTRIBUTION for
contribution
guide.
Distributed under the MIT License © wajeht. See LICENSE for more information.