Menu

1 / 3

Rate limiting in Node.js: fixed window and token bucket, with Express middleware

DEV Community: node·Mosaddik Billah·6 days ago
#Cp1W8Q7n
#devtonodejs#devto#dev#limit#const
Long article (1360 words) — no AI summary yet.
Reading 0:00
15s threshold

A rate limit caps how many requests one client can make in a period of time: say, 5 login attempts a minute, or 100 API calls a minute per key. Without one, a single script can guess passwords all night, scrape your whole catalogue, or run up your AI bill, and one busy client can slow the app down for everyone else. The examples below are Node.js rate limiting with Express middleware you can copy.

What to limit, and by what

Two choices define a limit:

The key : who counts as “one client”. Usually the API key or user ID when the request is signed in, and the IP address when it isn’t. IPs are shared (an office, a mobile network) and easy to change, so limits by IP should be generous.

The scope : which requests count.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.