DEV Community


Posted on

Redoc Documentation to ExpressJS

Redoc is an OpenAPI/Swagger-generated API Reference Documentation.

To install the redoc into your expressjs application install their npm package

npm i redoc-express

After installing the package, add a route for your swagger file and redoc api documentation

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

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

// serve swagger.json file
app.get('/docs/swagger.json', (req, res) => {
  res.sendFile('swagger.json', { root: '.' });

// serve redoc
    title: 'API Docs',
    specUrl: '/docs/swagger.json'

app.listen(port, () => console.log(`Express app listening on port ${port}!`));

Thats it now you can access the redoc documentation in the url http://localhost:3000/docs

Discussion (0)