npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

router-fusion

v1.2.2

Published

Include all the router files and add it in the app router without doing it manually by importing all the router files..

Downloads

21

Readme

router-fusion

Dynamically fuses routes from JavaScript and TypeScript files into an Express application.

Express Fusion simplifies Express.js development by automating route integration. This tool dynamically fuses routes from JavaScript and TypeScript files, eliminating the need for manual imports. Tailor integration effortlessly with optional parameters like exclusion filters and project paths. Explore the experimental "/help" route for insightful JSON-based API endpoint references. Ideal for boosting productivity and maintaining a clean codebase, Express Fusion is the go-to solution for a seamless Express.js development experience. Say goodbye to manual route imports.

Key Features:

  • Dynamic Integration: Automatically fuse routes from your JavaScript and TypeScript files into your Express application. Say goodbye to tedious manual imports!

  • Effortless Configuration: Customize route fusion with ease using optional parameters such as exclusion filters and project paths. Tailor the integration to fit your project's unique structure effortlessly.

  • Experimental "/help" Route: Gain unprecedented visibility into your integrated routes with the experimental "/help" route. Visualize your endpoints in a JSON format, providing developers with a quick reference guide. Please note: while this feature is incredibly powerful, it's currently experimental and may not be compatible with certain global authentication middleware setups.

Installation

npm install router-fusion

Usage

CommonJS Syntax

const express = require("express");
const { fuseRoutes } = require("router-fusion");

const app = express();

// Fuse routes into the Express application
fuseRoutes({
  app,
  // Optional: Exclude files and folders
  excludeFilter: "path/to/exclude folder1 folder2 file1.js",
  // Optional: Set the base path for the project (defaults to the current working directory)
  projectPath: __dirname,
  // Experimental: Include the "/help" route (defaults to false)
  // read more below
  helpRoute: true,
});

// Start the Express server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});

ES6 Syntax

import express from "express";
import { fuseRoutes } from "router-fusion";

const app = express();

// Fuse routes into the Express application
fuseRoutes({
  app,
  // Optional: Exclude files and folders
  excludeFilter: "path/to/exclude folder1 folder2 file1.js",
  // Required in ES6: Set the base path for the project (defaults to the current working directory)
  projectPath: import.meta.dirname,
  // Experimental: Include the "/help" route (defaults to false)
  // read more below
  helpRoute: false,
});

// Start the Express server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});

Experimental Feature: "/help" Route

The package includes an experimental feature that allows you to include a "/help" route in your Express application. This route provides a JSON representation of the integrated Express routes, making it convenient for developers to understand the available endpoints. Note that this feature is experimental and may not work as expected if your project has a global middleware for authentication. In such cases, it is recommended to evaluate its compatibility with your specific authentication setup.

const express = require("express");
const { fuseRoutes } = require("router-fusion");

const app = express();

// Fuse routes into the Express application with the "/help" route (experimental)
fuseRoutes({
  app,
  helpRoute: true,
});

// Start the Express server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});

API

fuseRoutes(options)

Dynamically fuses routes from JavaScript and TypeScript files into an Express application.

Parameters

  • options (object):
    • app (Express.Application): The Express application to which routes will be added.
    • excludeFilter (string, optional): A space-separated string containing files and folders to be excluded.
    • projectPath (string, optional for commonjs & required for ES6): The base path for the project. If not provided, it defaults to the current working directory.
    • helpRoute (boolean, optional): Experimental - Whether to include the "/help" route. Defaults to false.

Example

CommonJS Syntax

const express = require("express");
const { fuseRoutes } = require("router-fusion");

const app = express();

// Fuse routes into the Express application (only app provided)
fuseRoutes({ app });

// Fuse routes into the Express application with additional options
fuseRoutes({
  app,
  excludeFilter: "path/to/exclude folder1 folder2 file1.js",
  projectPath: __dirname,
  helpRoute: true,
});

ES6 Syntax

import express from "express";
import { fuseRoutes } from "router-fusion";

const app = express();

// Fuse routes into the Express application with additional options
fuseRoutes({
  app,
  excludeFilter: "path/to/exclude folder1 folder2 file1.js",
  projectPath: import.meta.dirname,
  helpRoute: true,
});

Error Handling

The module throws an error if there's an issue reading directories or fusing routes. Make sure to handle errors appropriately in your application.

try {
  fuseRoutes({ app });
} catch (error) {
  console.error("Error fusing routes to application:", error);
  // Handle the error as needed
}

Contributing

Feel free to contribute by submitting issues or pull requests on the GitHub repository.

License

This project is licensed under the MIT License - see the LICENSE file for details.