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

esbuild-dev-router

v0.7.2

Published

Express middleware for development with esbuild — fast in-memory bundling and automatic page reloading

Readme

esbuild-dev-router

Express middleware for development with esbuild. Bundles your source files in memory, serves them directly, and reloads the page automatically when you save.

Installation

npm install -D esbuild-dev-router

Peer dependency: Your project must also have esbuild installed (any version above 0.17).

Quick Start

Server

import express from 'express';
import devRouter from 'esbuild-dev-router';
import { resolve } from 'path';

const app = express();
app.listen(5000);

// Mount at the root — see "Mount Path" section below
app.use(devRouter({
    entryPoints: [resolve(__dirname, 'web/index.ts')]
}));

app.use(express.static(resolve(__dirname, 'public')));

HTML

Reference the bundled output by filename. If your entry point is web/index.ts, esbuild will produce index.js:

<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="/index.css">
</head>
<body>
    <script src="/index.js"></script>
</body>
</html>

A reload script is automatically injected into every bundle — no extra <script> tag needed. When you save a file, the page reloads.

How It Works

  1. Builds in memory — esbuild compiles your code with write: false, so nothing is written to disk. Built files are held in memory and served directly by the router.
  2. Watches for changes — esbuild's watch mode detects file changes and triggers a rebuild.
  3. Reloads the browser — A small script injected into each bundle opens a Server-Sent Events (SSE) connection to the /reloader endpoint. When a build completes, the server emits an event and the browser reloads the page.

Mount Path

The injected reload script connects to /reloader as an absolute path. This means the router must be mounted at the root of your Express app:

// Correct — mounted at root
app.use(devRouter({ ... }));

// Will NOT work — /reloader becomes /assets/reloader
app.use('/assets', devRouter({ ... }));

API

devRouter(options)

Accepts an esbuild BuildOptions object and returns an Express Router.

The router handles two routes:

  • GET /reloader — SSE endpoint that emits reload events after each build
  • GET /:filename — Serves the in-memory build output, with the correct content type

Default Options

The following defaults are applied and can be overridden through the options object:

| Option | Default | Notes | |---|---|---| | bundle | true | | | target | 'es2022' | | | sourcemap | 'inline' | | | minify | false | | | outdir | 'dist' | Used for path resolution only; files are never written to disk | | loader | { '.png': 'file', '.jpg': 'file' } | Merged with your custom loaders | | logLevel | 'info' | |

Options you provide are merged on top of these defaults, with two exceptions:

  • loader — your loaders are merged with the defaults (not replaced)
  • plugins and inject — your entries are appended alongside the built-in ones

The write option is always set to false and cannot be overridden.

Imports

// Default import (recommended)
import devRouter from 'esbuild-dev-router';

// Named import (if your setup has trouble with default imports)
import { devRouter } from 'esbuild-dev-router';

// The BuildOptions type is also re-exported for convenience
import { BuildOptions } from 'esbuild-dev-router';

Example: Custom Loaders and Target

app.use(devRouter({
    entryPoints: [resolve(__dirname, 'web/index.ts')],
    target: 'es2020',
    loader: {
        '.svg': 'file',
        '.woff2': 'file',
    }
}));

This overrides the default target and adds .svg and .woff2 loaders alongside the built-in .png and .jpg loaders.

Console Output

On each build, the router logs:

  • The filename of each .js and .css output file
  • A count of other assets (images, fonts, etc.)

Requirements

  • Node.js 18+
  • esbuild >0.17
  • Express 4.x or 5.x

License

Apache License 2.0