express-throttle-requests

Simulate slow http responses using Node & Express

Usage no npm install needed!

<script type="module">
  import expressThrottleRequests from 'https://cdn.skypack.dev/express-throttle-requests';
</script>

README

express-throttle-requests

build status npm version

Simulate slow http responses using Node & Express.

Easy to setup and use in your express app. Express middleware that resolves the http request after a random number of seconds. (Default between 50ms and 3000ms)

DO NOT USE THIS IN PRODUCTION.

THIS TOOL WAS DESIGNED TO SIMULATE SLOW REQUESTS/RESPONSES FROM THE SERVER

Usage

Usage with express app


var app = express();
var throttle = require('express-throttle-requests');

throttle(app);

Usage with express router


var router = express.Router();
var throttle = require('express-throttle-requests');

throttle(router);

Development environment only example


var router = express.Router();
if(config.env === 'development'){
  var throttle = require('express-throttle-requests');
  throttle(router);
}

Options

By default the requests will be throttled between 50ms and 3000ms. These values can be overriden.

min - Minimum time to wait for request

max - Maximum time to wait for request


var app = express();
var throttle = require('express-throttle-requests');

throttle(app, {
  min:1000, //Example showing a minimum of 1000ms (1 second)
  max:5000 //Example showing a maximum of 5000 (5 seconds)
});

Installation

With npm do

$ npm install express-throttle-requests --save-dev

License

(MIT)

Copyright (c) 2015 David Boyne

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.