🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

api-delay

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

api-delay

Deliberately cause a delayed http response in an express app.

1.0.1
unpublished
latest
Source
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

api-delay

Build Status Build status

What?

  • Deliberately cause a delayed http response in an express app.

Why?

  • Simulate a slow api response to test front end handling.
  • Throttle api access to abusers, non-premium users, etc.

How?

  • Creates a function that can be used as app middleware or a route handler.
  • Set the time and trigger options to customize the delayed call to next().

When?

Installation

npm install api-delay

Testing

npm test

Usage

'use strict';

// create express app
const app = require('express')();

// get configurable middleware
const { delayNext, delayNextIf } = require('api-delay');

// will add a 200 millisecond delay in express request/response
const middleWareDelay = delayNext({ time: 200 });

// will add a 500 millisecond delay in express request/response if trigger function returns truthy
const conditionalMiddleWareDelay = delayNextIf({
  time: 500,
  trigger: receiver => {
    // if username is falsey, expression returns truthy to trigger delay
    return !receiver.req.body.username;
  }
});

// add as middleware to all routes
app.use(middleWareDelay);

// add as a handler to a specific route
app.all('/somepath', [conditionalMiddleWareDelay], (req, res) => {
  res.send('some_response');
});

See more usage in docs, examples, and tests

Keywords

express

FAQs

Package last updated on 11 Aug 2019

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