bad-server
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

bad-server

A middleware that will degrade your express server's performance.

Why would you want this?

Developers often forget to account for API issues when building applications. Sometimes there might be network issues, sometimes the server might be unreachable for some reason. This middleware will help you build applications that are resilient to such situations by forcing you to handle them in development.

Installation

npm install bad-server

Usage

import { badServer } from "bad-server";

Application Level

app.use(badServer());

Route level

router.get("/api", badServer(), (req, res, next) => res.send("Hello World"));

Options

badServer accepts a single options parameter that you can use to configure how the middleware should work. The default options are used if no options are specified.

Option Default Description
delay - Fixed amount of delay for the response in milliseconds, takes precedence over maxDelay
maxDelay 250 Variant amount of delay for the response in milliseconds
failRate 0.1 (10%) A number between 0 and 1 expressing the likelyhood of rejecting a request with a 500 error
httpStatus - Causes the request to resolve with the specified HTTP status code and response
response - Response body used with httpStatus

Examples

Responding to requests with a 3-second delay

badServer({ delay: 3000 });

Responding to requests with a random delay up to 1 second

badServer({ maxDelay: 1000 });

Rejecting 50% of the requests

badServer({ failRate: 0.5 });

Responding with custom status code and response body

badServer({ httpStatus: 401, response: "Invalid Credentials" });

Dependencies (0)

    Dev Dependencies (10)

    Package Sidebar

    Install

    npm i bad-server

    Weekly Downloads

    4

    Version

    0.3.0

    License

    MIT

    Unpacked Size

    7.38 kB

    Total Files

    6

    Last publish

    Collaborators

    • luizchagas