{"id":17894,"library":"redoc-express","title":"ReDoc Express Middleware","description":"redoc-express is a lightweight Express middleware designed to serve interactive API documentation using the ReDoc UI from OpenAPI/Swagger specifications. The current stable version is 2.1.3, last published 6 months ago, indicating active maintenance. It provides a simple, single-middleware setup to integrate professional-grade API documentation into Node.js Express applications without requiring complex build tools. A key differentiator is its first-class TypeScript support with comprehensive type definitions, 100% test coverage, and compatibility with Node.js 6+ (ES5) and Express 4.x/5.x. It supports both OpenAPI 3.0+ and Swagger 2.0 specifications. The package focuses on ease of use, offering sensible defaults and extensive customization options via ReDoc's configuration, including built-in CSP nonce support for enhanced security.","status":"active","version":"2.1.3","language":"javascript","source_language":"en","source_url":"https://github.com/AungMyoKyaw/redoc-express","tags":["javascript","redoc","express","middleware","openapi","swagger","api-documentation","api-docs","documentation","typescript"],"install":[{"cmd":"npm install redoc-express","lang":"bash","label":"npm"},{"cmd":"yarn add redoc-express","lang":"bash","label":"yarn"},{"cmd":"pnpm add redoc-express","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This package is an Express middleware and requires Express.js to function. It is compatible with Express 4.x and 5.x.","package":"express","optional":false}],"imports":[{"note":"The main middleware function is a named export, not a default export.","wrong":"import redoc from 'redoc-express';","symbol":"redoc","correct":"import { redoc } from 'redoc-express';"},{"note":"For CommonJS, use object destructuring as 'redoc' is a named export.","wrong":"const redoc = require('redoc-express');","symbol":"redoc","correct":"const { redoc } = require('redoc-express');"},{"note":"TypeScript users can import type definitions for configuring ReDoc options.","symbol":"RedocOptions","correct":"import { RedocOptions } from 'redoc-express';"}],"quickstart":{"code":"import express from 'express';\nimport { redoc } from 'redoc-express';\nimport path from 'path';\n\nconst app = express();\nconst port = process.env.PORT || 3000;\n\n// A minimal OpenAPI spec for demonstration\nconst openApiSpec = {\n  openapi: '3.0.0',\n  info: {\n    title: 'My Awesome API',\n    version: '1.0.0',\n    description: 'An example API to demonstrate redoc-express',\n  },\n  paths: {\n    '/hello': {\n      get: {\n        summary: 'Says hello',\n        responses: {\n          '200': {\n            description: 'A greeting message',\n            content: {\n              'application/json': {\n                schema: {\n                  type: 'object',\n                  properties: {\n                    message: { type: 'string' }\n                  }\n                },\n                example: { message: 'Hello, World!' }\n              }\n            }\n          }\n        }\n      }\n    }\n  },\n  components: {\n    schemas: {}\n  }\n};\n\n// Serve the OpenAPI spec as a JSON file\napp.get('/openapi.json', (req, res) => {\n  res.json(openApiSpec);\n});\n\n// Mount the redoc-express middleware\napp.use(\n  '/docs',\n  redoc({\n    title: 'API Documentation',\n    specUrl: '/openapi.json', // URL where your OpenAPI spec is served\n    redocOptions: {\n      theme: {\n        colors: { primary: { main: '#607d8b' } },\n        typography: {\n          fontFamily: 'Montserrat, sans-serif'\n        }\n      }\n    }\n  })\n);\n\n// Basic route for the API itself\napp.get('/hello', (req, res) => {\n  res.json({ message: 'Hello, World!' });\n});\n\napp.listen(port, () => {\n  console.log(`Server running on http://localhost:${port}`);\n  console.log(`API Docs available at http://localhost:${port}/docs`);\n  console.log(`API Endpoint: http://localhost:${port}/hello`);\n});\n","lang":"typescript","description":"This quickstart sets up a basic Express server, serves a minimal OpenAPI 3.0 specification, and integrates `redoc-express` to display interactive API documentation at the '/docs' endpoint. It demonstrates passing configuration options to ReDoc for customization."},"warnings":[{"fix":"Ensure your OpenAPI spec (JSON or YAML) is served at an HTTP/HTTPS endpoint, and provide that URL to `redoc-express` via the `specUrl` option. For local files, create an Express route like `app.get('/openapi.json', (req, res) => res.sendFile('path/to/spec.json'));`","message":"The `specUrl` option for `redoc-express` expects a publicly accessible URL to your OpenAPI specification, not a local file path. If your spec is a local file, you must serve it via another Express route or a static file server first.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always review the `redoc` library's release notes when updating `redoc-express` to check for changes in available options or their structure. Validate your `redocOptions` configuration against the latest `redoc` documentation.","message":"Breaking changes in the underlying ReDoc library (which `redoc-express` uses) might affect the `redocOptions` configuration. While `redoc-express` API tends to be stable, the shape of the `redocOptions` object can change between major ReDoc versions.","severity":"breaking","affected_versions":"Consult `redoc` release notes"},{"fix":"If you have a strict CSP, ensure that the policy allows scripts from `cdn.jsdelivr.net` (or wherever ReDoc assets are loaded from) and permits the execution of the necessary inline scripts. Use the `nonce` option in `redoc-express` if your CSP requires nonces: `redoc({ ..., nonce: res.locals.cspNonce })`.","message":"Incorrect Content Security Policy (CSP) headers on your server might block ReDoc from loading external resources or executing inline scripts, leading to a blank page or errors in the console. `redoc-express` offers `nonce` support.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Run `npm install redoc-express` or `yarn add redoc-express` in your project directory.","cause":"The 'redoc-express' package has not been installed or is not correctly linked in your project.","error":"Error: Cannot find module 'redoc-express'"},{"fix":"Verify that the `specUrl` points to a valid and accessible OpenAPI JSON/YAML file. Test the URL directly in your browser. Ensure your server is running and configured to serve the spec at that endpoint, and that CORS policies allow the ReDoc page to fetch it if hosted on a different domain.","cause":"The ReDoc UI could not fetch the OpenAPI specification from the `specUrl` provided. This often happens if the URL is incorrect, the server serving the spec is unreachable, or there are CORS issues.","error":"Something went wrong... Failed to fetch"},{"fix":"Validate your OpenAPI specification using an online validator (e.g., Swagger Editor or Redocly CLI `lint` command) to identify and correct any syntax or structural errors before serving it.","cause":"The OpenAPI specification provided is not valid YAML or contains syntax errors.","error":"YAMLException: failed to parse YAML"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}