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

@uppercut-labs/static-file-server

v0.2.0

Published

Dependency-free Node static file server with a path-traversal guard, MIME map, range requests and optional SPA fallback.

Readme

@uppercut-labs/static-file-server

Serves a folder over HTTP from Node with no dependencies. It rejects path traversal (including encoded dots and symlinks that leave the folder), sends the right content type, answers range requests so video can seek, and can fall back to index.html for client-side routes. It works as a function you call from code and as a small command line tool.

npm install @uppercut-labs/static-file-server
import { startStaticServer } from '@uppercut-labs/static-file-server';

const site = await startStaticServer({ root: './dist', spaFallback: true });
console.log(site.url); // http://127.0.0.1:<free port>
// ...
await site.close();

To use your own server, or to answer some routes yourself first, build a handler:

import { createServer } from 'node:http';
import { createStaticHandler } from '@uppercut-labs/static-file-server';

const handle = createStaticHandler({ root: './dist', cleanUrls: true });
createServer((req, res) => void handle(req, res)).listen(3000);

Stub routes, test controls and extra folders fit in two options:

const site = await startStaticServer({
  root: './dist',
  cleanUrls: true,
  // Answer a request yourself: return true when you did.
  before: (req, res) => {
    if (req.url === '/api/contact') {
      res.writeHead(405).end('disabled');
      return true;
    }
    return false;
  },
  // Serve another folder under a URL prefix.
  mounts: { '/media': './media-files' },
});

Command line:

npx static-file-server ./dist --port 8080 --spa

Functions

| Function | Returns | | --- | --- | | startStaticServer(options) | Promise<{ server, host, port, url, close() }>, listening | | createStaticServer(options) | an http.Server, not yet listening | | createStaticHandler(options) | (request, response) => Promise<void> | | resolveStaticPath(root, urlPath) | { ok: true, file, isDirectory } or { ok: false, problem } where problem is bad-request, forbidden or not-found | | parseRange(header, size) | { start, end }, 'unsatisfiable', or null to send the whole file | | contentTypeFor(file, extra?) | content type string | | MIME_TYPES | the built-in extension table |

Options

| Option | Default | Meaning | | --- | --- | --- | | root | required | Folder to serve | | port | 0 | Port for startStaticServer; 0 picks a free one | | host | 127.0.0.1 | Interface for startStaticServer | | index | index.html | Index file name | | spaFallback | false | Send the index file for unknown paths without an extension. { exclude: ['/api'] } keeps prefixes out | | cleanUrls | false | Try <path>.html and <path>/index.html. When a folder and a <path>.html page share a name, the page is served (as in a static export) | | ranges | true | Answer Range requests with 206 and 416 | | cacheControl | no-cache | A string, or a function of the URL path | | headers | none | Extra response headers, or a function of the file path | | mime | none | Extra content types by extension | | notFoundFile | none | File sent with 404 responses | | blockDotfiles | false | 404 for any path segment that starts with a dot | | basePath | none | URL prefix the site is served under | | allowedHosts | any | Accepted Host names; others get 403 | | onRequest | none | Called with { method, path, status, served } for each request | | before | none | (request, response) => boolean \| Promise<boolean>, called after the allowedHosts check. Return true when the hook answered the request; anything else lets it continue. Handled requests are not reported to onRequest. A throw becomes a 500 | | mounts | none | { '/prefix': './folder' }: serve more folders under URL prefixes with the same guard, ranges, headers and caching. The longest prefix wins, a mount shadows same-named files in root, and spaFallback never applies to a mount |

Only GET and HEAD are accepted; other methods get 405. A directory requested without a trailing slash is redirected with 301, and the query string is kept.

Changed in 0.2.0: added before and mounts; with cleanUrls, <path>.html is now served instead of a redirect when a folder has the same name; redirects keep the query string (0.1.0 dropped it).

Command line flags: --port, --host, --spa, --clean-urls, --no-ranges, --cache, --dotfiles. Paths with dot segments are hidden unless --dotfiles is given.

Errors

startStaticServer rejects if the port cannot be bound. Requests never throw: bad paths get 400, paths outside the root get 403, and read failures get 500.

License

MIT