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

nodejs-middleware

v1.1.8

Published

Node.js Middleware

Readme

Middleware

Common Parameter Middleware Async Example

const { commonParamatersMiddlewareAsync } = require("nodejs-middleware") //CommonJS
import { commonParamatersMiddlewareAsync } from "nodejs-middleware" //Module


async function one(req, res, next, returns) {
  console.log(req, res, next, returns)
  await asyncFunc()
  console.log("one async")
  return next(2222)
}

async function two(next_data, req, res, next, returns) {
  console.log(2, next_data, req, res, next, returns)
  await asyncFunc()
  console.log("two async")
  return next()
}

async function three(next_data, req, res, next, returns) {
  console.log(3, next_data, req, res, next, returns)
  await asyncFunc()
  console.log("three async")
  return returns(100, 2, 4, 5, 6, 4)
}

function asyncFunc() {
  return new Promise((resolve) => {
    setTimeout(() => {
      console.log("waited")
      return resolve()
    }, 2000);
  })
}

async function testing() {
  const result = await commonParamatersMiddlewareAsync(one, two, three)("req", "res")
  console.log(result)
  console.log("finish")
}

testing()
//Output
/*
req res [Function: next] [Function: returns]
waited
one async
2 2222 req res [Function: next] [Function: returns]
waited
two async
3 2222 req res [Function: next] [Function: returns]
waited
three async
[ 100, 2, 4, 5, 6, 4 ]
finish
*/

Common Parameter Middleware Sync Example

const { commonParamatersMiddlewareSync } = require("nodejs-middleware") //CommonJS
import { commonParamatersMiddlewareSync } from "nodejs-middleware" //Module


function one(req, res, next, returns) {
  console.log(1, req, res, next, returns)
  return next(222222)
}

function two(next_data, req, res, next, returns) {
  console.log(2, next_data, req, res, next, returns)
  next()
}

function three(data, req, res, next, returns) {
  console.log(3, data, req, res, next, returns)
  return returns(100, 2, 4, 5, 6, 4)
}


function testing() {
  const result = commonParamatersMiddlewareSync(one, two, three)("req", "res")
  console.log(result)
  console.log("finish")
}

testing()

//Output
/**
1 req res [Function: next] [Function: returns]
2 222222 req res [Function: next] [Function: returns]
3 222222 req res [Function: next] [Function: returns]
[ 100, 2, 4, 5, 6, 4 ]
finish
 */

Sync Example

const { middlewareSync } = require("nodejs-middleware") //CommonJS
import { middlewareSync } from "nodejs-middleware" //Module

function one(first, next, returns) {
  console.log(1, first, next, returns)
  return next(222222)
}

function two(other, second, next, returns) {
  console.log(2, other, second, next, returns)
  return next()
}

function three(data, next, returns) {
  console.log(3, data, next, returns)
  return returns(100, 2, 4, 5, 6, 4)
}

function testing() {
  const result = middlewareSync(one, two, three)(10, 20, 30)
  console.log(result) //output -> [ 100, 2, 4, 5, 6, 4 ]
  console.log("finish")
}

testing()

//Output
/*
1 10 [Function: next] [Function: returns]
2 222222 20 [Function: next] [Function: returns]
3 30 [Function: next] [Function: returns]
[ 100, 2, 4, 5, 6, 4 ]
finish
*/

Async Example

const { middlewareAsync } = require("nodejs-middleware") //CommonJS
import { middlewareAsync } from "nodejs-middleware" //Module

async function one(first, next, returns) {
  console.log(1, first, next, returns)
  await asyncFunc()
  console.log("one async")
  return next(2222)
}

async function two(other, second, next, returns) {
  console.log(2, other, second, next, returns)
  await asyncFunc()
  console.log("two async")
  return next()
}

async function three(data, next, returns) {
  console.log(3, data, next, returns)
  await asyncFunc()
  console.log("three async")
  return returns(100, 2, 4, 5, 6, 4)
}

function asyncFunc() {
  return new Promise((resolve) => {
    setTimeout(() => {
      console.log("waited")
      return resolve()
    }, 2000);
  })
}

async function testing() {
  const result = await middlewareAsync(one, two, three)(10, 20, 30)
  console.log(result) //output -> [ 100, 2, 4, 5, 6, 4 ]
  console.log("finish")
}

testing()

//Output
/*
1 10 [Function: next] [Function: returns]
waited
one async
2 2222 20 [Function: next] [Function: returns]
waited
two async
3 30 [Function: next] [Function: returns]
waited
three async
[ 100, 2, 4, 5, 6, 4 ]
finish
*/