DEV Community

Vignesh
Vignesh

Posted on

1

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)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay