@wajeht/express-templates-reload
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

🔄 express-templates-reload

Node.js CI npm License: MIT Open Source Love svg1 npm

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

📜 License

Distributed under the MIT License © wajeht. See LICENSE for more information.

Package Sidebar

Install

npm i @wajeht/express-templates-reload

Weekly Downloads

0

Version

1.0.3

License

MIT

Unpacked Size

14.2 kB

Total Files

7

Last publish

Collaborators

  • wajeht