DEV Community

Vignesh
Vignesh

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
Enter fullscreen mode Exit fullscreen mode

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
app.get(
  '/docs',
  redoc({
    title: 'API Docs',
    specUrl: '/docs/swagger.json'
  })
);

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

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

Top comments (0)