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

@prexjs/serve-static

v1.0.0

Published

Static file serving middleware for Node.js, Express, and Prex with redirect, index, and header controls.

Readme

@prexjs/serve-static

Static file serving middleware for Node.js, Express, and Prex with redirect, index, and header controls.

npm version npm downloads License: MIT TypeScript

@prexjs/serve-static is a Connect/Express-compatible middleware for serving static assets from a root directory. Powered internally by @prexjs/send, it handles automatic directory redirects, custom headers, caching headers, and non-blocking fallthrough.

Features

  • Connect & Prex Compatible: Drop-in middleware for Prex, Express, or standard http.createServer stacks.
  • Directory Trailing-Slash Redirects: Automatically issues HTTP 301 redirects with proper URL escaping for directory paths without trailing slashes.
  • Fallthrough Support: Seamlessly passes control to subsequent route handlers or error middleware when files are not found.
  • Custom Header Hooks: setHeaders(res, path, stat) callback to inject headers based on file type or metadata.
  • High Performance: Powered by stream pipelines with native RFC caching and byte-range support.

Installation

Install using your preferred package manager:

# npm
npm install @prexjs/serve-static

# pnpm
pnpm add @prexjs/serve-static

# Yarn
yarn add @prexjs/serve-static

# Bun
bun add @prexjs/serve-static

Quick start

import http from 'node:http';
import serveStatic from '@prexjs/serve-static';

// Serve files from the "public" directory
const serve = serveStatic('public', {
  index: ['index.html'],
  maxAge: '1d',
  setHeaders: (res, path) => {
    if (path.endsWith('.html')) {
      res.setHeader('Cache-Control', 'public, max-age=0');
    }
  },
});

const server = http.createServer((req, res) => {
  serve(req, res, (err) => {
    if (err) {
      res.statusCode = 500;
      res.end('Internal Server Error');
      return;
    }

    // Fallthrough: route was not matched by a static file
    res.statusCode = 404;
    res.end('Not Found');
  });
});

server.listen(3000);

API

serveStatic(root, [options])

Returns a standard Connect-style middleware (req, res, next) => void.

  • root: Root directory string from which files will be served.
  • options:
    • fallthrough: When true, errors or missing files pass through via next() rather than ending response with 404 (default: true).
    • redirect: Redirect to trailing slash when pathname is a directory (default: true).
    • setHeaders: Callback function (res, path, stat) => void for adding headers.
    • dotfiles: How to treat dotfiles ('allow', 'deny', 'ignore').
    • etag: Enable/disable etag generation.
    • extensions: File extension fallbacks (e.g., ['html', 'htm']).
    • index: Index file name (default: 'index.html').
    • maxAge: Max-age in milliseconds or string format (default: 0).

Compatibility

  • Node.js >= 18.0.0
  • Supports both ESM and CommonJS
  • TypeScript 5.0+

Related Packages

License

MIT