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

@jrh-works/route

v1.0.0

Published

Basic HTTP request and response handling for Node.js.

Readme

@jrh-works/route

Basic HTTP request and response handling for Node.js.

For a quickstart, see the usage example.

Installation

npm install @jrh-works/route

The Routing Configuration Function

Usage

const { configureRoute } = require('@jrh-works/route')

Syntax

configureRoute(options)

Arguments

| Name | Type | Description | | :-- | :-- | :-- | | options | Object: Options | Configuration options for the handling function. |

Returns

| Type | Description | | :-- | :-- | | Function: Route | A configured route function. |

Exceptions

Throws a standard Error if:


The Options Object

| Attribute | Type | Description | | :-- | :-- | :-- | | log | Function: Log | A log function which will be used to log request and response information. |


The Log Function

A function for logging information.

The function should include the properties .error() for logging errors and .request() for logging from an HTTP Request object.

Example Syntax
function log(value) {
  console.log(value)
}

log.error = (error) => {
  console.error(error)
}

log.request = (request) => {
  console.log(request.method, request.url)
}

The Route Function

Syntax

route(handler)

Arguments

| Name | Type | Description | | :-- | :-- | :-- | | handler | Function: Handler | A handler function to execute. |

Returns

No return value.

Exceptions

Throws a standard Error if:

  • A handler function is not present.

Effects

  • Information about the request and response will be logged using the log function.

The Handler Function

Syntax
handle(request, response)

Arguments

| Name | Type | Description | | :-- | :-- | :-- | | request | Object: HTTP Request | A standard HTTP Request object. | | response | Object: HTTP Response | A standard HTTP Response object. |

Returns

| Type | Description | | :-- | :-- | | Number | Object: RouteResponse | The value which will determine the HTTP response. |

Returning a Number

If the handler returns a number, the route will respond with that status (i.e. 200). To include a JSON response in addition to a status, return a RouteResponse.

Exceptions

If the handler throws a standard error:

  • The error will be logged using the log function.
  • The route will respond with a 500 status.

If the handler throws a handler error:

  • The route will respond with the status in the handler error.

The RouteResponse Object

| Attribute | Type | Description | | :-- | :-- | :-- | | status | Number | An HTTP status code to send. | | data | Object | String | Data to send as a JSON response body. |


The Handler Error

The handler error can be thrown from within a handler function to customize the error status.

Usage

const { handlerError } = require('@jrh-works/route')

Syntax
handlerError(message, options)
Arguments

| Name | Type | Description | | :-- | :-- | :-- | | message | String | An error message. | | options | Object: ErrorOptions | Configuration for the handler error. |


The ErrorOptions Object

| Attribute | Type | Description | | :-- | :-- | :-- | | status | Number | An HTTP error status code. |


Usage Example

const { configureRoute, handlerError } = require('@jrh-works/route')
const log = require('./my-logger')

const route = configureRoute({ log })

const handler = (request, response) => {
  if (request.header('Authorization') !== process.env.API_KEY) {
    throw handlerError('Unauthorized request.', { status: 401 })
  }

  return 200
}

module.exports = route(handler)