🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis
Socket
Book a DemoInstallSign in
Socket

middy-js

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package version was removed
This package version has been unpublished, mostly likely due to security reasons

middy-js

Middleware magic ✨ for Express, Fastify & Node.js – modular, fast, and delightful!

unpublished
npmnpm
Version
5.0.8
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

Middy.js 🛡️

npm version License: MIT

The Modern Node.js Middleware Toolkit - A lightweight, modular middleware system for Express and beyond.

Features ✨

  • 🧩 Plugin-based architecture - Compose middleware like building blocks
  • Performance optimized - Low overhead middleware execution
  • 🔌 Universal adapter - Works with Express, Fastify, and vanilla Node.js
  • 📦 Batteries included - Common middleware utilities included
  • 🛠️ TypeScript ready - Full type definitions out of the box

Installation

npm install middy-js
# or
yarn add middy-js
# or
pnpm add middy-js

Basic Usage

const { Middy } = require('middy-js');
const express = require('express');

const app = express();
const middy = new Middy(app);

// Add middleware
middy.use((req, res, next) => {
  console.log('Request received at', new Date());
  next();
});

// Add error handler
middy.onError((err, req, res, next) => {
  console.error(err);
  res.status(500).send('Something broke!');
});

app.get('/', (req, res) => {
  res.send('Hello Middy!');
});

app.listen(3000);

Core Concepts

Middleware Chains

middy.use([
  // Authentication
  require('@middy/auth'),
  
  // Request validation
  require('@middy/validator'),
  
  // Response formatting
  require('@middy/format-response')
]);

Built-in Middleware

Middy.js comes with several useful middleware:

  • bodyParser - Parse JSON/URL-encoded bodies
  • cors - Cross-Origin Resource Sharing
  • helmet - Security headers
  • logger - Request logging
  • rateLimit - Rate limiting
const { bodyParser, cors } = require('middy-js/middleware');

middy.use([
  cors(),
  bodyParser()
]);

Advanced Usage

Custom Middleware

function myMiddleware(config) {
  return {
    before: (req, res, next) => {
      // Pre-request logic
      req.startTime = Date.now();
      next();
    },
    after: (req, res, next) => {
      // Post-request logic
      console.log(`Request took ${Date.now() - req.startTime}ms`);
      next();
    }
  }
}

middy.use(myMiddleware({ option: true }));

Framework Adapters

// Fastify adapter
const fastify = require('fastify');
const { FastifyMiddy } = require('middy-js/adapters');

const app = fastify();
const middy = new FastifyMiddy(app);

Benchmarks

FrameworkRequests/secLatency (ms)
Plain Express15,6781.21
Middy.js14,8921.34
Connect14,1201.45

Benchmarks run on Node 18, 2.4GHz Quad-Core Intel Core i5

Ecosystem

Official plugins:

  • @middy/auth - Authentication utilities
  • @middy/cache - Request/response caching
  • @middy/validator - Request validation
  • @middy/swagger - OpenAPI/Swagger integration

Keywords

log

FAQs

Package last updated on 04 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts