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

chaos-injector

v1.0.0

Published

Chaos engineering middleware for testing API resilience

Readme

Chaos Injector

Inject chaos into your Express.js APIs to test resilience and fault tolerance.

Overview

Chaos Injector is a lightweight Node.js library designed to simulate real-world failure scenarios in your Express applications. By injecting delays, errors, timeouts, and empty responses, it helps you test the resilience and reliability of your APIs under unpredictable conditions.

Features

  • 🧪 Inject HTTP errors dynamically
  • 🐢 Simulate random response delays
  • ⏳ Simulate timeouts
  • 🛑 Inject empty or missing responses
  • ⚙️ Highly configurable (or use ready-made chaos profiles)
  • 🛠️ Minimal setup — simple middleware integration

Installation

npm install chaos-injector

Usage

const express = require('express');
const { withChaos } = require('chaos-injector');

const app = express();

// Apply chaos injection to a route
app.get('/', withChaos('flakyNetwork'), (req, res) => {
  res.send('Hello, Chaos!');
});

app.listen(3000, () => console.log('Server running on port 3000'));

API

withChaos(profileName?, userConfig?)

| Parameter | Type | Description | |---------------|--------|--------------------------------------------------| | profileName | string | (Optional) Name of a predefined chaos profile | | userConfig | object | (Optional) Custom configuration that overrides the profile |

Returns an Express middleware function that injects chaos according to the configuration.

Configuration Options

| Option | Type | Description | |-------------------|---------------------|--------------------------------------------------------------| | failureRate | number (0-1) | Probability of injecting a failure (default: 0.0) | | delayRange | [min, max] array | Delay response randomly between min and max (ms) | | errorTypes | string[] | Array of HTTP error status codes to simulate | | emptyType | string | Type of empty response: 'empty', 'empty_object', 'empty_array', or 'no_data' | | simulateTimeout | boolean | If true, simulates a timeout without sending a response |

Chaos Profiles

Predefined profiles for quick setup:

| Profile | Behavior | |----------------------|-----------------------------------------------------------| | flakyNetwork | Random delays (300-1500ms) + occasional 503, 504 errors | | overloadedServer | Heavy delays (1200-4000ms) + frequent server errors | | gremlinAttack | High error rate across various HTTP error codes | | intermittentEmpty| Frequent empty successful responses | | timeoutScenario | Very high chance of timeout without a response | | latencySpike | Extreme delays (2000-8000ms) without errors | | errorStorm | Frequent server-side errors | | emptyTrap | Intermittent empty object responses |

Example: Using a Predefined Profile

app.get('/chaos', withChaos('gremlinAttack'), (req, res) => {
  res.send('Chaos injected!');
});

Example: Using Custom Configuration

app.get('/test', withChaos({
  delayRange: [100, 300],
  failureRate: 0.2,
  errorTypes: ['500', '400']
}), (req, res) => {
  res.send('This might be slow or fail sometimes.');
});

Error Handling

  • If a configured chaos event triggers, the middleware automatically sends a corresponding HTTP error or empty response.
  • If invalid config options are provided, the middleware calls next() with an Error.

Limitations

  • No dynamic adjustment of failure rate over time (planned for future releases).
  • No input validation on user config (planned for future enhancement).

Contributing

Contributions are welcome! 🚀 Please feel free to:

  • Submit bug reports
  • Suggest new chaos profiles
  • Improve documentation
  • Add test coverage

To contribute, fork the repository, make your changes, and submit a pull request.

License

This project is licensed under the MIT License.

✨ Why Chaos Injector?

"Everything fails, all the time." — Werner Vogels, CTO, Amazon.

Test your services like they live in the real, messy, unpredictable internet. 🌎

Author

Created with ❤️ by Gopal Vallu.