express-better-ratelimit
Version:
Express.js request rate limit middleware by IP with MemoryStore
31 lines (24 loc) • 714 B
JavaScript
/**
* express-better-ratelimit <https://github.com/tunnckoCore/express-better-ratelimit>
*
* Copyright (c) 2014 Charlike Mike Reagent, contributors.
* Released under the MIT license.
*/
;
var express = require('express');
var limit = require('./index');
var app = express();
app.use(limit({
duration: 30000, //30 seconds
max: 5
//blackList: ['127.0.0.1']
}));
app.use(function helloWorld(req, res, next) {
res.set('Content-Type', 'text/plain');
res.status(200).send('Hello world');
next();
});
var port = process.env.PORT || 3333;
app.listen(port);
console.log('Express server start listening on port %s', port);
console.log('Type few times: curl -i http://localhost:%s', port);