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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@openovate/express-router

v0.0.17

Published

Express routing with priority settings.

Readme

express-router

Express routing with priority settings.

Install

$ npm i --save @openovate/express-router

Usage

It is generally similar to express.Router.

const express = require('express');
const Router = require('@openovate/express-router');

const router = Router();

router.get('/some/path', (req, res) => {
  res.send('Hello World');
});

const app = express();
app.use(router);

app.listen(3000);

The basic route can be formed in several ways.

router.route('/').get((req, res) => {
  res.send('Hello World');
});

// ... or ...

router.get('/', (req, res) => {
  res.send('Hello World');
});

// ... both above actually calls ...

router.route('get', '/', (req, res) => {
  res.send('Hello World');
});

// ... and that actually calls ...

router.on('GET /', (req, res) => {
  res.send('Hello World');
});

Async/Await

You can use async callbacks now it will still properly order by when it was defined.

router.get('/some/path', async(req, res) => {
  await something();
});

router.get('/some/path', (req, res) => {
  res.send('Done');
});

Priority

You can specify higher priority routes (negative priorities work too).

router.get('/some/path', (req, res) => {
  console.log('Run After');
});

router.get('/some/path', (req, res) => {
  console.log('Run Before');
}, 100);

No next()

With async/await there is no need for next() anymore. To pass an error to the express handler, just throw it.

router.get('/some/path', (req, res) => {
  throw new Error('Something happened...');
});

app.use(function (err, req, res) {
  res.status(500).send(err.message);
});

RouteTo ...

Routes can now invoke other routes manually with routeTo()

router.get('/some/path', async (req, res) => {
  await router.routeTo('get', '/some/other', req, res);
});

router.route('/some/other').get((req, res) => {
  res.send('Some other route');
});

Introducing stage, rest and content

stage is a combination of the URL query, form post and URL path parameters. rest is different than res.json() where it gives other routes an opportunity to add on to the rest data before sending it out. stage and rest use Registry from the JSM library. For a quick study, see: @openovate/jsm#registry-usage

The rationale for content is the same as rest where it is different than res.write() and res.send() where it gives other routes an opportunity to add on to the content data before sending it out.

// -> GET /some/path?foo[bar][]=zoo
router.get('/some/path', async (req, res) => {
  if (!req.stage.has('foo', 'bar', 0)) {
    req.stage.set('foo', 'bar', 0, 'zoo');
  }

  const foo = req.stage.get('foo', 'bar', 0);

  res.rest
    .set('error', false)
    .set('results', foo);

  // ... or ...
  res.content.set(foo);
});

Events with Priorities too ...

Router extends EventEmitter from the JSM library. For a quick study, see: @openovate/jsm#eventemitter-usage

router.on('do something', (req, res) => {
  console.log('Run After');
});

router.on('do something', (req, res) => {
  console.log('Run Before');
}, 100);

router.on('something else', (req, res) => {
  const foo = req.stage.get('foo');
  res.rest.set('results', foo);
});

router.get('/some/path', async (req, res) => {
  await router.emit('do something', req, res);
  const results = await router.request('something else', { foo: 'bar' });
  res.send(results); //-> bar
});