Lesson 17 — Rate limiting an endpoint
Too many requests
A rate limiter protects an endpoint (one URL of your API) from being called too often — by a bug or an attacker. The simplest one counts calls and refuses after a maximum. Real servers answer refused calls with status 429 Too Many Requests.
const hit = limiter(3);
hit(); hit(); hit(); hit(); // ok ok ok blocked
Why it matters: without limits, one script can slow the site down for everyone.
Finish limiter(): return "ok" while count < max (then count up), otherwise "blocked".
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
A quick 3-question quiz on this lesson — instant feedback.
Ready for more? Optional paid resources that pick up where this lesson leaves off.
Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.
Project-based Node.js Foundations courses if you want a structured paid path after the free lessons. Wait for a sale — prices drop often.
Browse on Udemy →Search Amazon for Node.js Foundations books — check the publication year so the examples match current versions.
Search Amazon →