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 🙏

© 2025 – Pkg Stats / Ryan Hefner

in-route

v1.0.3

Published

A web route matching library built to read from a simplistic configuration

Readme

in-route

license npm version vulnerabilities downloads build status

A web route matching library built to read from a simplistic configuration

Getting Started

In Route can be used as a simple front end router, such as for React applications and other approaches. Or, this package can be used in tandem with packages like the HTTP module or Express.js to create an API. It's fairly lightweight and effective at handling complex routes that may inlude paramters, queries, etc.

Installation

npm install in-route

Features

  • Mapping for all HTTP methods
  • Automatic parsing of parameters, query strings, and path
  • Custom variable object passed along with each route
  • Case sensitive and case insensitive routes
  • Ready to plug in with Node's HTTP module or the Express module

API


Router(routes[, config])

Router constructor.

Parameters

  • routes (Object) Routes object.
  • config (Object) Config object.
    • caseSensitive (Boolean) True if routes should be handled with case sensitivity, otherwise false. Defaults to true.
    • defaultAction (Function) Default action to execute if a route is not handled. Defaults to an empty function.

handle(uri[, method[, body[, headers[, httpObject]]]])

Parses a route and executes the action tied to the route, passing request and response objects to the action.

Parameters

  • uri (String) URI to handle and parse
  • method (String) HTTP method in uppercase. Defaults to GET
  • body (Object) Request body object passed from HTTP library.
  • headers (Object) Headers object passed from HTTP library.
  • httpObject (Object) Object containing HTTP library's request and response object's structured as { req: <requestObject>, res: <responseObject> }

Examples

const Router = require('in-route');
const routes = require('path-to-routes-export');

const router = new Router(routes, {
  caseSensitive: true,
  defaultAction: (req, res) => { console.log('default', { req, res }); },
});

router.handle('http://www.example.uri/param1?query1=true', 'GET', bodyObj, headersObj, { req: reqObj, res: resObj });

Example Routes object

/*
Request object:
{
  vars: Object,
  body: Object,
  headers: Object,
  query: Object,
  params: Object,
  url: String,
  path: String,
  method: String,
  extraPath: String,
  httpRequest: Object, // HTTP module or Express request object
}

The response object is the response from the HTTP module/Express
*/
module.exports = {
  'GET /': {
    action: (req, res) => { return res.send({ query: req.query, params: req.params, vars: req.vars, body: req.body }); },
    vars: 'home',
  },
  'post /hi': {
    action: (req, res) => { return res.send({ query: req.query, params: req.params, vars: req.vars, body: req.body }); },
  },
  'GET /hi/': {
    action: (req, res) => { return res.send({ query: req.query, params: req.params, vars: req.vars, body: req.body }); },
    vars: {},
  },
  'GET /hi/{hello_id}': {
    action: (req, res) => { return res.send({ query: req.query, params: req.params, vars: req.vars, body: req.body }); },
    vars: {
      hasVar: true,
    },
  },
  // Method keyword is optional. Defaults to GET
  'hi/{hello_id}/yEs': {
    action: (req, res) => { return res.send({ query: req.query, params: req.params, vars: req.vars, body: req.body }); },
    vars: {
      thing: 'Yes this is a thing',
      pizza: ['pep', 'chez', '!pineapple'],
    },
  },
  'delete /hi/{hello_id}/YES/{yes_id}/': {
    action: (req, res) => { return res.send({ query: req.query, params: req.params, vars: req.vars, body: req.body }); },
  },
  'get /hi/{hello_id}/YES/{yes_id}/': {
    action: (req, res) => { return res.send({ query: req.query, params: req.params, vars: req.vars, body: req.body }); },
    vars: {
      crazy: true,
    }
  }
};

Contributing

Please read CONTRIBUTING.md before submitting issues and merge requests.

License

MIT