DEV Community

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

Posted on

1

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

Top comments (0)

Billboard image

Try REST API Generation for MS SQL Server.

DevOps for Private APIs. With DreamFactory API Generation, you get:

  • Auto-generated live APIs mapped from database schema
  • Interactive Swagger API documentation
  • Scripting engine to customize your API
  • Built-in role-based access control

Learn more

πŸ‘‹ Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Communityβ€”every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple β€œthank you” goes a long wayβ€”express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay