Production-ready • 136 tests • 100% coverage

Serve beautiful
API docs with
Express + ReDoc

A lightweight Express middleware that mounts interactive ReDoc documentation from your OpenAPI/Swagger spec. Zero config, full TypeScript support, CSP-friendly.

100% test coverage 136 passing tests MIT License npm downloads
npm install redoc-express

Why redoc-express?

Minimal overhead, zero config, fully customizable. Just mount and go.

Lightweight & Fast

Serves a static HTML shell that pulls your spec at runtime. Zero overhead.

TypeScript First

Complete type definitions and modern TS-friendly API out of the box.

100% Test Coverage

136 comprehensive test cases with full code coverage and daily CI runs.

Zero Config

Drop-in middleware with sensible defaults. Customize only what you need.

CSP-ready

Built-in nonce support for strict Content Security Policies.

OpenAPI & Swagger

Supports OpenAPI 3.x and Swagger 2.0 specifications.

Quick start

1

Install the package

Using npm, yarn, or pnpm

2

Serve your OpenAPI/Swagger spec

As JSON from any endpoint

3

Mount the middleware

Point it to your spec URL

const express = require('express');
const redoc = require('redoc-express');

const app = express();
const port = 3000;

// Serve your OpenAPI/Swagger spec
app.get('/docs/swagger.json', (req, res) => {
  res.sendFile('swagger.json', { root: '.' });
});

// Mount ReDoc middleware
app.get('/docs', redoc({
  title: 'API Documentation',
  specUrl: '/docs/swagger.json'
}));

app.listen(port, () => {
  console.log(`📚 Docs at http://localhost:${port}/docs`);
});

What you get

  • Beautiful, interactive API reference powered by ReDoc
  • CSP-friendly HTML with optional nonce support
  • Works with OpenAPI 3.x or Swagger 2.0
  • Fully typed API for TypeScript users
ReDoc configuration docs

Enterprise-grade testing

Comprehensive test suite with 136 test cases and 100% code coverage.

Unit Tests

85+
  • HTML structure validation
  • Title & URL handling
  • Nonce validation
  • JSON serialization
  • ReDoc options

Middleware Tests

51+
  • Express integration
  • Request handling
  • Response chaining
  • Immutability checks
  • Edge cases

E2E Tests

26+
  • Real-world scenarios
  • Concurrent requests
  • Multiple versions
  • Stress testing
  • Route isolation
100%

Code Coverage

136

Test Cases

~2s

Execution Time

0

Lint Errors

Advanced configuration

Customize theme, behavior, and more with ReDoc options

Advanced example with theme customization
app.get('/docs', redoc({
  title: 'My API Documentation',
  specUrl: 'https://api.example.com/openapi.json',
  nonce: 'random-nonce-123', // Optional: CSP compliance
  redocOptions: {
    theme: {
      colors: { primary: { main: '#6EC5AB' } },
      typography: {
        fontFamily: '"Inter", sans-serif',
        fontSize: '15px'
      }
    },
    hideDownloadButton: true,
    expandResponses: '200,201'
  }
}));

Frequently asked questions

Does it support TypeScript?
Yes! Full TypeScript support with included type definitions (.d.ts files).
Which specs are supported?
Both OpenAPI 3.x and Swagger 2.0 specifications are fully supported.
What about security (CSP)?
Built-in nonce support lets you run under strict Content Security Policies without issues.
Node/Express version support?
Node 6+ (ES5 compiled output). Works with Express 4.x and 5.x.