🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

connect-pause

Connect/Express middleware to simulate latency for debugging

0.1.0
latest
Version published
Weekly downloads
234K
-1.86%
Maintainers
1
Weekly downloads
 
Created

What is connect-pause?

The connect-pause npm package is a middleware for Connect/Express that allows you to introduce a delay in the processing of HTTP requests. This can be useful for simulating network latency or testing how your application behaves under slow network conditions.

What are connect-pause's main functionalities?

Introduce a fixed delay

This feature allows you to introduce a fixed delay (in milliseconds) for all incoming HTTP requests. In this example, a 2-second delay is added to all requests.

const express = require('express');
const pause = require('connect-pause');

const app = express();

// Introduce a 2-second delay for all requests
app.use(pause(2000));

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

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

Conditional delay

This feature allows you to introduce a delay conditionally, for example, only for specific routes. In this example, a 3-second delay is added only to requests to the '/slow' route.

const express = require('express');
const pause = require('connect-pause');

const app = express();

// Introduce a delay only for specific routes
app.use('/slow', pause(3000));

app.get('/slow', (req, res) => {
  res.send('This response is delayed by 3 seconds');
});

app.get('/fast', (req, res) => {
  res.send('This response is fast');
});

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

Other packages similar to connect-pause

FAQs

Package last updated on 22 May 2013

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