DEV Community

Cover image for Express limit rate API request
Le Hong Son
Le Hong Son

Posted on

Express limit rate API request

Today I want to share my experience improve my backend node app with an express framework with a limited rate query user request.
demo API query

Hurry up!! let start

step 1: install module express-rate-limit

yarn add express-rate-limit

step 2: now, we need to import the library into our application

const rateLimit = require("express-rate-limit")

step 3: define variable inlude timer and number limit request

const limiter = rateLimit({
windowMs: 1 * 60 * 1000, // 15 minutes
max: 10 // limit each IP to 100 requests per windowMs
})

step 4: use limiter as middleware of expressjs

app.use(limiter);
alt text

Congratulation !! you finished improving your security rest API

Latest comments (0)