npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@wajeht/express-templates-reload

v3.0.0

Published

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

Downloads

651

Readme

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 WebSockets for instant reloads

🛠️ Installation

$ npm install @wajeht/express-templates-reload --save-dev

Usage

app.listen() apps

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') {
  const reload = 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 server and browser console logs
    },
  });

  process.on('SIGTERM', () => reload.dispose());
}

app.get('/', (req, res) => res.send('Hello, world!'));

app.listen(80, () => console.log('App is listening on http://localhost'));

Custom http.createServer(app) apps

If you create the HTTP server yourself, pass it in so the WebSocket upgrade handler can attach to that server:

import http from 'node:http';
import express from 'express';
import { expressTemplatesReload } from '@wajeht/express-templates-reload';

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

expressTemplatesReload({
  app,
  server,
  watch: [{ path: './views', extensions: ['.html'] }],
});

server.listen(80);

Dynamic import in an app factory

This pattern works too. If the app later starts with app.listen(...), passing app is enough. If it later starts with a custom server, pass server at that point instead.

import path from 'node:path';
import express from 'express';

export async function createApp() {
  const app = express();

  if (process.env.NODE_ENV === 'development') {
    try {
      const { expressTemplatesReload } =
        await import('@wajeht/express-templates-reload');

      expressTemplatesReload({
        app,
        watch: [
          {
            path: path.join(process.cwd(), 'src/public'),
            extensions: ['.css', '.js'],
          },
          {
            path: path.join(process.cwd(), 'src/routes'),
            extensions: ['.html'],
          },
        ],
        options: { quiet: true },
      });
    } catch (error) {
      console.warn('Express templates reload could not be initialized', error);
    }
  }

  return app;
}

API Reference

expressTemplatesReload(config)

Returns an ExpressTemplatesReloadHandle with a dispose() method for closing watchers, WebSocket state, and restoring patched app methods.

Config Options

| Parameter | Type | Description | | --------------------- | ------------- | --------------------------------------------------- | | app | Application | Express application instance | | server | Server | Optional HTTP/HTTPS server for custom server setups | | 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 server logs and browser logs by default | | options.clientQuiet | boolean | Override browser console logging behavior |

watch[].path is resolved from the current process working directory. If your app can start from different directories, prefer absolute paths.

Docs

License

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