1.0.4 • Published 4 months ago
@wajeht/express-templates-reload v1.0.4
🔄 express-templates-reload
automatically reload the browser for template and public asset changes in an express app
🛠️ Installation
$ npm install @wajeht/express-templates-reload --save-dev
💻 Usage
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'));
🛠️ API Reference
expressTemplatesReload(config)
Config Options
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) |
📑 Docs
- See DEVELOPMENT for
development
guide. - See CONTRIBUTION for
contribution
guide.
📜 License
Distributed under the MIT License © wajeht. See LICENSE for more information.