Skip to content

lawrence14701-zz/express-ddos-protector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DDOS_protector

Bucket strategy

Protects Api from malicious users.

To use this npm package please do $npm i bucket-ddos

import the npm package

const Limiter = require('express-bucket-rate-limiter');

This package works as a callback function, to use it please refer to this example.

const express = require('express');
const Limiter = require('express-ddos-protector');
const limit = new Limiter();
const app = express();
const port = 3000;

// Apply to all requests
app.get('/', limit.limitRequests(1, 2, 1000), (req, res) => {
	const Blacklist = limit.Blacklist;
	if (Blacklist.includes(req.ip)) {
		res.send('access denied');
	} else {
		res.send('hello world');
	}
});

app.listen(port, () => console.log(`Example app listening on port ${port}!`));

limiter function takes in three parameters (perSecond, maxReq, timeInMs)

perSecond represents how fast you are filling the bucket per second

maxReq represents the max amount of req a bucket can hold.

In the above example I am filling the bucket once per second. If the user depletes the bucket quicker than it can fill up than he will be inserted in a blackList array. The bucket size in this example is two and I am filling the bucket once every 1000 ms (1 second)

Github Link

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published