Socket
Socket
Sign inDemoInstall

bad-server

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    bad-server

A middleware that will degrade your express server's performance. For development purposes only.


Version published
Weekly downloads
13
increased by30%
Maintainers
1
Install size
7.21 kB
Created
Weekly downloads
 

Readme

Source

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.

OptionDefaultDescription
delay-Fixed amount of delay for the response in milliseconds, takes precedence over maxDelay
maxDelay250Variant amount of delay for the response in milliseconds
failRate0.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" });

Keywords

FAQs

Last updated on 28 Apr 2021

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc