Member-only story

How to list all routes in ExpressJs

Bhavya Dhiman
2 min readApr 8, 2023

--

If you are not subscribed to Medium Membership, you can click this link:

https://medium.com/@bhavyadhiman7/how-to-list-all-routes-in-expressjs-95009172ea10?sk=dfc6a9d9a04f2a74b852acf930b81302

If you are building an application in ExpressJs, You might need to define the routes for documenation (for example swagger), but sometimes due to the complexity (especially in large projects) of the application and routes in most of the applications are nested, it is very difficult to list all apis manually.

Fortunately there is an npm package which is express-list-endpoints which make our job easier.

Here is the documentation for the same: https://github.com/AlbertoFdzM/express-list-endpoints.

I will give you a sample example:

const express = require('express');
const listEndpoints = require('express-list-endpoints');
const app = express();
app.listen(3000);
const endPoints = require('express-list-endpoints');



app.get('/users', () => {});

app.get('/books', () => {});


app.get('/routes', (req, res) => {
res.status(200).send(endPoints(app));
});

After running the code, if you start the application, the GET /routes API will return the following result:

[
{
"path": "/users",
"methods": […

--

--

No responses yet