DEV Community

Saksham Singh
Saksham Singh

Posted on

TrailXpress: My New NPM Package

NPM Package

Photo by Paul Esch-Laurent on Unsplash

A while ago, I created Routes-Explorer to help developers extract and visualize Express routes effortlessly. While it served its purpose, I saw opportunities for improvement so I built TrailXpress.

Routes-Explorer is no longer maintained, and all future development will continue under TrailXpress. If you were using Routes-Explorer, I highly recommend switching over.

You can install it from here: https://www.npmjs.com/package/trailxpress

GitHub link: https://github.com/Saksham294/trailxpress

Usage

Installation

npm install trailxpress
To use this package, include it in your Node.js project and call the getRoutes function with the path to your Express API file.

const { getRoutes } = require('trailxpress');
const apiFilePath = 'path/to/your/api/file.js';
try {
  const routes = getRoutes(apiFilePath);
  console.log('Extracted Routes:', routes);
} catch (error) {
  console.error('Error:', error.message);
}
Enter fullscreen mode Exit fullscreen mode

Filtering Routes by HTTP Method

You can filter routes based on request types (GET, POST, PUT, DELETE, etc.).

const { getRoutes } = require('trailxpress');
const apiFilePath = 'path/to/your/api/file.js';
const filteredRoutes = getRoutes(apiFilePath, ['GET', 'POST']); // Only fetch GET and POST routes
console.log(filteredRoutes);
Enter fullscreen mode Exit fullscreen mode

Swagger Documentation Generation

TrailXpress can generate Swagger documentation for your API.

const { generateSwagger } = require('trailxpress');
const apiFilePath = 'path/to/your/api/file.js';
const routes = getRoutes(apiFilePath);
const swaggerDocs = generateSwagger(routes);
console.log(swaggerDocs);
Enter fullscreen mode Exit fullscreen mode

I have some plans to further improve TrailXpress. If you face any issues, have suggestions or feature request, you can comment below or raise an issue here.

If you found it useful you can star it too (it means a lot :D )

I’d love to hear your feedback and learn how TrailXpress can be improved to enhance your developer experience.

Hope you found it helpful.

Any suggestions are highly welcome, thank you for reading.

Feel free to connect with me on other platforms: LinkedIn GitHub Twitter

Top comments (0)