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

alt text

Congratulation !! you finished improving your security rest API

Top comments (0)

An Animated Guide to Node.js Event Loop

Node.js doesn’t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.

What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.