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

Postgres on Neon - Get the Free Plan

No credit card required. The database you love, on a serverless platform designed to help you build faster.

Get Postgres on Neon

Top comments (0)

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay