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

stoplight-express-custom

v0.5.0

Published

Express middleware for Stoplight Elements API docs (local bundle)

Readme

stoplight-express-custom

Express middleware that serves Stoplight Elements API docs from a Swagger 2 / OpenAPI document (same shape as swagger-ui-express).

Every script and stylesheet is bundled in the package and served by your own app. There is no CDN, no remote font/JS fetch, and no inline <script> — the browser only loads assets from the same origin as the docs. That makes the UI a good fit for APIs behind a strict Content-Security-Policy (for example script-src 'self' without 'unsafe-inline' or extra host allowlists).

npm: stoplight-express-custom

Install

yarn add stoplight-express-custom
# or
npm install stoplight-express-custom

Peer dependency: express >= 4

Alternative (GitHub)

# Yarn 4
yarn add stoplight-express-custom@github:RodriguesWall/stoplight-express-custom

# npm / Yarn classic
npm install git+https://github.com/RodriguesWall/stoplight-express-custom.git

Quick start

const express = require('express')
const stoplightExpress = require('stoplight-express-custom')
const swaggerDocument = require('./swagger.json') // or your OpenAPI object

const app = express()

app.use(
  stoplightExpress({
    title: 'My API Documentation',
    export: true,
    // poweredBy omitted → footer hidden
    config: swaggerDocument,
  })
)

app.listen(3000)

TypeScript / ESM:

import express from 'express'
import stoplightExpress from 'stoplight-express-custom'
import swaggerDocument from './docs/swagger'

app.use(
  stoplightExpress({
    title: 'MPS API Documentation',
    export: true,
    poweredBy: 'powered by Mailspike', // optional; omit or "" to hide
    config: swaggerDocument,
  })
)

Then open:

| URL | What | | --- | --- | | /docs | Stoplight Elements UI | | /docs/swagger.json | Spec JSON | | /docs/assets/* | Elements static assets |

Every URL lives under docsPath, and the HTML references them with relative URLs. A single reverse-proxy rule for /docs* is enough, and the docs keep working when the proxy serves them under a prefix (https://host/api/docs).

Options

| Option | Type | Default | Description | | --- | --- | --- | --- | | config | object | required | Swagger 2 / OpenAPI document | | title | string | "API Documentation" | HTML <title> | | export | boolean | true | Show OpenAPI export button (false → hideExport) | | poweredBy | string | "" (hidden) | Footer text. Omit or empty → no footer. Example: "powered by Mailspike" | | docsPath | string | "/docs" | Docs UI path | | swaggerPath | string | `${docsPath}/swagger.json` | Spec JSON path. An absolute path outside docsPath opts out of relative URLs | | assetsPath | string | `${docsPath}/assets` | CSS/JS static path. An absolute path outside docsPath opts out of relative URLs | | router | "hash" \| "history" \| "memory" | "hash" | Elements router | | layout | "sidebar" \| "stacked" | "sidebar" | Elements layout | | theme | "dark" \| "light" \| "system" | "dark" | Initial color theme. "system" follows the OS preference | | themeToggle | boolean | true | Show the floating dark/light toggle button | | search | boolean | true | Show the sidebar endpoint filter input | | searchPlaceholder | string | "Filter endpoints…" | Placeholder text for the filter input | | methodIcons | boolean | true | Per-method sidebar icon (circle/square/diamond/triangle for GET/POST/PUT-PATCH/DELETE) instead of the default bullseye |

Theme

The docs render in dark mode by default, and a round toggle button in the bottom-right corner switches between dark and light:

stoplightExpress({
  config: swaggerDocument,
  theme: 'dark', // "dark" (default) | "light" | "system"
  themeToggle: true, // false → no button, `theme` is always enforced
})
  • Only an actual click on the toggle is remembered (localStorage key stoplight-express-custom:theme), and that choice wins over theme on later visits. With themeToggle: false nothing is remembered and theme always applies. Elements' own mosaic-theme entry is written so its internal state matches, but never read — otherwise the light mode it stores by default would override theme.
  • The theme is applied on <html data-theme="..."> before the first paint, so there is no flash of the wrong theme on load.
  • system resolves in the browser; server-rendered HTML starts from dark so the page still looks right with JavaScript disabled.
  • base.css also fixes the code samples in dark mode: Elements keeps using its light syntax palette there (navy strings on a dark canvas), so its own dark palette is re-applied, and required markers use the readable warning color.

Publishing updates

Bump version in package.json, then:

npm publish --access public

Consumers:

yarn up stoplight-express-custom
# or
yarn add stoplight-express-custom@^0.4.1

Notes

  • config must be a plain object (Swagger 2 or OpenAPI 3). Mutating it after mount (e.g. info.version) still works if you pass the same object reference.
  • Assets are served from the package static/ folder (elements.min.js / elements.min.css / base.css / theme.js). See Local assets and CSP.
  • poweredBy is injected via <docsPath>/assets/powered-by.js (external script). Omit or pass "" to hide the footer; there is no “powered by Stoplight” label by default.
  • Your reverse proxy only needs to forward /docs and everything under it to the Node process. Prefix rewrites (/api/docs → /docs) are supported — the page resolves its own assets relative to the URL the browser used.

License

MIT

Repo: RodriguesWall/stoplight-express-custom