Lightweight Express middleware for serving interactive ReDoc API documentation from OpenAPI/Swagger specs. TypeScript support, 100% test coverage, ES5 compatible.
Lightweight Express middleware for serving interactive ReDoc API documentation from OpenAPI/Swagger specs with full TypeScript support and zero configuration overhead.
redoc-express makes it dead simple to add professional API documentation to your Express server. Unlike alternatives:
npm install redoc-express
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(`📚 API docs available at http://localhost:${port}/docs`);
});
import express, { Express } from 'express';
import redoc from 'redoc-express';
const app: Express = express();
const port = 3000;
// Serve your OpenAPI/Swagger spec
app.get('/docs/swagger.json', (req, res) => {
res.sendFile('swagger.json', { root: '.' });
});
// Mount ReDoc middleware with TypeScript support
app.get(
'/docs',
redoc({
title: 'API Documentation',
specUrl: '/docs/swagger.json',
redocOptions: {
theme: {
colors: {
primary: { main: '#1976d2' }
}
}
}
})
);
app.listen(port, () => {
console.log(`📚 API docs available at http://localhost:${port}/docs`);
});
app.get(
'/docs',
redoc({
title: 'My API Documentation',
specUrl: 'https://api.example.com/openapi.json',
nonce: 'random-nonce-123', // Optional: for CSP compliance
redocOptions: {
theme: {
colors: {
primary: { main: '#6EC5AB' }
},
typography: {
fontFamily: '"museo-sans", Helvetica, Arial, sans-serif',
fontSize: '15px'
},
menu: { backgroundColor: '#ffffff' }
},
hideDownloadButton: true,
expandResponses: '200,201,400'
}
})
);
For all available ReDoc configuration options, see the official documentation
| Option | Type | Required | Description |
|---|---|---|---|
title | string | Yes | Title displayed in the browser tab and header |
specUrl | string | Yes | URL to your OpenAPI/Swagger specification file |
nonce | string | No | Security nonce for Content Security Policy compliance |
redocOptions | object | No | ReDoc configuration options |
npm i
npm test
npm run build
| Metric | Coverage |
|---|---|
| Statements | 100% |
| Branches | 100% |
| Functions | 100% |
| Lines | 100% |
136 comprehensive test cases organized across 3 test suites:
Unit Tests - redocHtml (85+ tests)
Unit Tests - redocExpressMiddleware (51+ tests)
End-to-End Tests (26+ tests)
npm test # Run all 136 tests
npm test -- --coverage # With coverage report
npm test -- --watch # Watch mode during development
All tests pass with 100% code coverage in approximately 1-2 seconds.
Q: Can I use this with TypeScript? A: Yes! Full TypeScript support with included type definitions.
Q: Does this work with OpenAPI 3.0? A: Yes, both OpenAPI 3.0+ and Swagger 2.0 are supported.
Q: Is there a performance impact? A: Minimal. The middleware only serves static HTML—no runtime overhead.
Q: Can I customize the UI colors/fonts?
A: Yes, pass redocOptions with your theme configuration.
Q: What Node.js versions are supported? A: Node 6+ (ES5 compiled output). Development requires Node 18.14+.
MIT © Aung Myo Kyaw