Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
connect-pause
Advanced tools
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.
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');
});
The express-delay package provides similar functionality to connect-pause by allowing you to introduce delays in your Express application. It offers more granular control over the delay, such as random delays within a specified range. Compared to connect-pause, express-delay provides more flexibility in simulating various network conditions.
The express-slow-down package is designed to slow down responses based on request rate. It is useful for rate limiting and preventing abuse by introducing delays after a certain number of requests. While connect-pause is more focused on introducing fixed delays, express-slow-down is more dynamic and adjusts delays based on request patterns.
Connect/Express middleware to simulate latency for debugging
npm install connect-pause
Pause all Connect requests:
var connect = require('connect'),
pause = require('connect-pause');
Connect.createServer(
pause(1000),
function(req, res, next){
res.writeHead(200, {'Content-Type':'text/plain'});
res.end('Waited 1 second');
}
).listen(8080);
Pause all Express requests:
var express = require('express'),
pause = require('connect-pause');
var app = express();
app.use(pause(1000));
app.get('/', function(req, res){
res.send('Waited 1 second');
});
app.listen(3000);
Pause a single Express endpoint:
var express = require('express'),
pause = require('connect-pause');
var app = express();
app.get('/', pause(1000), function(req, res){
res.send('Waited 1 second');
});
app.listen(3000);
Pass an error to be returned after the delay:
var express = require('express'),
pause = require('connect-pause');
var app = express();
app.get('/', pause(1000, new Error('Send 500')), function(req, res){
res.send('Waited 1 second');
});
app.listen(3000);
This middleware is meant to be used while developing and in need to simulate latency for certain requests or all.
(The MIT License)
Copyright (c) 2013 Ariel Flesler
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Connect/Express middleware to simulate latency for debugging
The npm package connect-pause receives a total of 0 weekly downloads. As such, connect-pause popularity was classified as not popular.
We found that connect-pause demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.