Skip to content

VladimirMikulic/route-list

Folders and files

NameName
Last commit message
Last commit date

Latest commit

4ac2e3c Β· Oct 24, 2024

History

22 Commits
Jan 11, 2023
Oct 19, 2022
Sep 14, 2024
Nov 1, 2022
Oct 24, 2024
Sep 14, 2024
Oct 19, 2022
Oct 19, 2022
Oct 16, 2022
Apr 20, 2023
Feb 4, 2023
Oct 24, 2024
Oct 24, 2024

Repository files navigation

route-list

Version License: MIT CI Twitter: VladoDev

✨ Beautifully shows Express/Koa/Hapi/Fastify routes in CLI.

route-list CLI example

πŸ“¦ Installation

# Installs the package so it's globally accessible in terminal
npm i route-list -g

πŸ”Œ Configuration

Before you can use route-list on your project, we first need to make sure it's configured properly. In order for route-list to work, we need to export server "app". The example below is for Express but it also applies to Koa (with @koa/router)/Hapi/Fastify.

app.js / app.ts

const app = express();

app.get('/', (req, res) => res.sendStatus(200));
app.get('/products', (req, res) => res.sendStatus(200));
app.get('/products/:id', (req, res) => res.sendStatus(200));

// CJS
// Option 1: module.exports = app;
// Option 2: module.exports = { app, yourOtherExports... };
// Option 3: module.exports = functionThatReturnsApp;

// ESM
// Option 1: export default app;
// Option 2: export default { app, yourOtherExports... };
// Option 3: export default functionThatReturnsApp;

NOTE: In case you use SocketIO with Express, make sure to export Express app, not http.createServer server instance.

☁️ Usage

Options

  • -g, --group - Display routes in groups separated with new line
  • -m, --methods <methods> - Include routes registered for HTTP method(s)
  • -i, --include-paths <paths> - Include routes starting with path(s)
  • -e, --exclude-paths <paths> - Exclude routes starting with path(s)

Examples

route-list server/app.js
route-list --group server/app.js
route-list --methods GET,POST server/app.js

NOTE: In case an app is part of NX monorepo, make sure to build it first.

πŸ’» Programmatic Usage

import RouteList from 'route-list';

// Example result { "/": ["GET"], "/users": ["GET", "POST"] }
const routesMap = RouteList.getRoutes(app, 'express');

// Print routes to console
RouteList.printRoutes(routesMap);

πŸ‘¨ Author

Vladimir Mikulic

🀝 Contributing

Contributions, issues and feature requests are welcome!

🍻 Credits

The project was inspired by new route:list command in Laravel 9. New route:list itself was inspired by pretty-routes project. Big thanks to Ξ›lex Wulf for building pretty-routes and Laravel community for recognizing the usefulness of the project.

✏️ License

This project is licensed under MIT license.

πŸ‘¨β€πŸš€ Show your support

Give a ⭐️ if this project helped you!