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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@barelyhuman/tiny-use

v0.0.2

Published

An asynchronous middleware based handler for node

Downloads

28

Readme

@barelyhuman/tiny-use

The tiniest middleware library for node's HTTP

Coverage

Invisible if you squint hard enough

Why ?

I've written this in my experimentals sink for over 1.5 years now, the first public version of the same is available here barelyhuman/http/middleware.

I made it to be small and contained to reduce the middleware's load on node's server.

With respect to:

  • Performace - It's linear and basically depends on what load you add in your actual middleware since it itself has no overhead.
  • Reason - Like everything else, I've written it more than once and reached a point of saturation where I don't want to reduce it's size in terms of code and functionality.
  • Stability - The API isn't going to change since it's very basic and ties to the Node API so unless that changes, makes no sense for this to change

Installation

; npm i --save @barelyhuman/tiny-use

Usage

Node HTTP API

To use with the default node:http/http API, you use it just like any other express js middleware, the difference being that the middleware now supports async flow

import http from 'node:http'
import { use } from '@barelyhuman/tiny-use'

http.createServer(
  use(
    async (req, res, next) => {
      req.value = 1
      await next()
      console.log({
        value: req.value,
      })
    },
    async (req, res, next) => {
      req.value = 2
      res.end('Final Message')
      return
    }
  )
)

Ecosystem

You don't have to rebuild an ecosystem, most of what connect has and what express uses should be usable.

Fetch Compliant API

If you work with network functions that are more inclined to the Fetch API standard and you need to use common middleware instead of manually calling them in each function call, you can do so by making minor modifications to the import

import { use } from '@barelyhuman/tiny-use/fetch'

const withMiddleware = use(
  req => {
    req.userId = 1
  },
  req => {
    return new Response(req.userId)
  }
)

export default {
  fetch: withMiddleware,
}

[!NOTE]:
When using the fetch based API, you might need to also add a bundling step if the tool you use doesn't do the bundling for you

License

MIT