Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-mega-router

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-mega-router

Express middleware allowing dynamic routes and middleware.

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

express-mega-router

A simple Express middleware that allows for dynamic routing and middleware.

It uses path-to-regexp for route parsing, thereby imposing all limitations inherent within.

Uses Babel for transpiling ES6 into ES5.

Installation

npm install express-mega-router --save

Usage

const express     = require('express');
const megaRouter  = require('express-mega-router')();

const app = express();
app.use(megaRouter.middleware);

Basic route

megaRouter.get('/test', function(req, res) {
  res.send('Test Route');
});

Catch all methods

megaRouter.all('/*', function(req, res, next) {
  console.log('catch-all engaged!');
  next();
});

One-time use route

function singleUseRoute(req, res) {
  res.send('Single-use route!');
  megaRouter.unget('/*', singleUseRoute);
});
megaRouter.get('/*', singleUseRoute);

Clearing all routes for a path

megaRouter.unget('/*');

Mixed route arguments

megaRouter.get('/*',
  function(req, res, next) {
    console.log('A');
    next();
  },
  function(req, res, next) {
    console.log('B');
    next();
  },
  [
    function(req, res, next) {
      console.log('C');
      next();
    },
    function(req, res, next) {
      console.log('D');
      next();
    }
  ]);

License

GPLv3

Keywords

FAQs

Package last updated on 10 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc