DEV Community

Ahmet İlhan
Ahmet İlhan

Posted on

2

Express IP Blocker

Express IP Blocker

https://www.npmjs.com/package/express-ip-blocker-current
https://github.com/ahmetilhan24/express-ip-blocker/blob/master/README.md

You can use this package to prevent continuous requests to APIs you write with Express.js within a certain period of time.

Instalation

package (yarn or npm)

    npm install express-ip-blocker
Enter fullscreen mode Exit fullscreen mode

PeerDependencies
Optimum versions

    "cookie-parser": "^1.4.6",
    "express": "^4.18.2"
Enter fullscreen mode Exit fullscreen mode

Usage

const express = require("express");
const app = express();
const cookieParser = require("cookie-parser");
const ExpressIPBlocker = require("express-ip-blocker-current");
const expressIPBlocker = new ExpressIPBlocker();
// You have to do this for the package to work
app.use(cookieParser());
// IP Middleware
app.use(expressIPBlocker.checkIP);

app.listen(//port, () => {
  //
});
Enter fullscreen mode Exit fullscreen mode

See demo for example usage. ./demo/index.js

Config

You can apply a config to the package's run settings

{
  limit: number; // default = 10
  secretKey: string; // default = now Date()
  reqBlockMessage: string; // default = Too Many Requests
  expire: number; // default = 1000 * 10 -> 10 second
}
Enter fullscreen mode Exit fullscreen mode

Coded by ahmetilhan

Billboard image

The fastest way to detect downtimes

Join Vercel, CrowdStrike, and thousands of other teams that trust Checkly to streamline monitoring.

Get started now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay