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

just-router

v1.0.9

Published

Compact, fast and simple node js router with no dependencies

Downloads

62

Readme

just-router

Clean, fast and simple node js router with no dependencies

const http = require('http');
const router = require('just-router');

http.createServer(router({
  '/': (req, res) => res.end('hello world!')
})).listen(80);

Installation

🍄 npm i just-router

Examples

Create routelist and add it to router like this

http.createServer(router({
  '/api/user/:id': {get: getUser, delete: deleteUser},
  '/api/user':     {post: createUser},
  '/src/::file':   {get: getStatic},
  '/':             {get: getIndex, other: elseIndex},
  '':              handle404
})).listen(80);

or like this

router({
  '/api/user/:id': {get: getUser, delete: deleteUser},
  '/api/user':     {post: createUser},
  '/src/::file':   {get: getStatic},
  '/':             {get: getIndex, other: elseIndex},
  '':              handle404
});

http.createServer(router).listen(80);

and then just handle the routes

function getUser(req, res) {     // GET '/api/user/1?key=2&edit'
  console.log(req.params);       // {id: '2'}
  console.log(req.query);        // {key: '3', edit: ''}
}

function deleteUser(req, res) {  // DELETE '/api/user/5'
  console.log(req.params);       // {id: '5'}
}

function createUser(req, res) {} // POST '/api/message'

function getStatic(req, res) {   // GET '/src/js/app.js'
  console.log(req.params);       // {file: '/js/app.js'}
}

function getIndex(req, res) {}   // GET '/'

function elseIndex(req, res) {}  // "any other method" '/'

function handle404(req, res) {}  // "all methods" all other requests

You can call router(newRouteList) whenever you want to change the routes to new ones

Documentation

Initialisation

const router = require('just-router');

router

router can be called with 1 or 2 arguments:

  • router(routeList)
    • accepts routeList
    • returns router which is waiting for 2 arguments
  • router(req, res)
    • accepts req and res from server's request

routeList

routeList is a simple object with routes

let routeList = {
	'/route': routeHandleFunction,
	'/route/2': routeHandleObject
}

route

route is a path template, which can include :variables or ends by ::pathEnding

/user/:userId/messages/:messageId will match

  • /user/1/messages/2 and req.params will be {userId: '1', messageId: '2'}
  • /user/Morty/messages/lol?token=777&debugMode
  • but NOT /user/1/messages and /user/1/2/messages/3

/src/::filePath will match

  • /src/img/logo.png and req.params will be {filePath: '/img/logo.png'}
  • /src/templates/widget/header.pug

Special routes

  • '/' is the "root route"
  • '' is the "others route" that catches all requests that did not match before

:variables/::pathEndings and ?search=string&values can be found in req.params and req.query objects respectively

::pathEndings values​start with the '/' character, and the :variables values​are not

routeHandleFunction and routeHandleObject

  • route: routeHandleFunction handles ALL request methods
  • route: routeHandleObject is an object whose keys are the names of the request methods or universal key 'other'. Its values are routeHandleFunctions
let routeHandleObject = {
	get: routeHandleFunction,
	post: routeHandleFunction2,
	other: routeHandleFunction3  // aliases: all || any || else || _
}

function routeHandleFunction(req, res) {}

If the methods did not match, then the other routeHandleFunction is called. other keyword has aliases: all, any, else and _

Match examples

/user/:id/message/:mId

|OK 👍|BAD IDEA 👎| |---|---| |/user/1/message/2|/user/1/message/| |/user/1/message/2/|/user/1//message/2| |/user//message//|/user/message/1| |/user/_/message/2?lol|/user/1/message/2/3| |/user/:id/message//?c=5&x|/user/:id/message/?c=5&x|

/api/::id

|OK 👍|BAD IDEA 👎| |---|---| |/api/1|/api/| |/api/////1//2|/api| |/api/a/b/c?lol=1&x=|/api?1| |/api//?1|/api/?1| |/api/1?1||

/id

|OK 👍|BAD IDEA 👎| |---|---| |/id|/id/id| |/id/|/?id| |/id?id|/id//| |/id/?ea||

Philosophy

just-router

  • is tiny and probably quickest
  • is NOT overloaded with additional functionality
  • has simple one-method syntax
  • has simple and beautiful routeList
  • takes care of your node_modules size
  • has no dependencies
  • 🍄