Skip to content

wajeht/express-templates-reload

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 using Server-Sent Events and Node.js streams for instant, efficient reloads

🛠️ 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
if (process.env.NODE_ENV === 'development') {
  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: {
      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.quiet boolean Suppress console logs (default: false)

Docs

License

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

About

automatically reload the browser for template and public asset changes in an express app

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors