0
0
Node.jsframework~10 mins

Rate limiting in Node.js - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the rate limiting middleware from the 'express-rate-limit' package.

Node.js
const rateLimit = require('[1]');
Drag options to blanks, or click blank then click option'
Aexpress-rate-limit
Bexpress-limit
Crate-limit-express
Dexpress-rate
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect package names like 'express-rate' or 'express-limit'.
Forgetting to install the package before importing.
2fill in blank
medium

Complete the code to create a rate limiter that allows 100 requests per 15 minutes.

Node.js
const limiter = rateLimit({ windowMs: [1], max: 100 });
Drag options to blanks, or click blank then click option'
A900000
B60000
C15000
D3600000
Attempts:
3 left
💡 Hint
Common Mistakes
Using seconds instead of milliseconds.
Confusing 15 seconds with 15 minutes.
3fill in blank
hard

Fix the error in applying the rate limiter middleware to an Express app.

Node.js
app.[1](limiter);
Drag options to blanks, or click blank then click option'
Arun
Blisten
Capply
Duse
Attempts:
3 left
💡 Hint
Common Mistakes
Using app.apply() or app.run() which do not exist.
Trying to use app.listen() to add middleware.
4fill in blank
hard

Fill both blanks to create a rate limiter that sends a custom message when the limit is exceeded.

Node.js
const limiter = rateLimit({ windowMs: 60000, max: 10, message: '[1]', statusCode: [2] });
Drag options to blanks, or click blank then click option'
AToo many requests, please try again later.
B429
C500
DRequest limit exceeded
Attempts:
3 left
💡 Hint
Common Mistakes
Using status code 500 which means server error.
Leaving the message blank or unclear.
5fill in blank
hard

Fill all three blanks to create a rate limiter that uses a custom key generator and skips requests from localhost.

Node.js
const limiter = rateLimit({ windowMs: 60000, max: 5, keyGenerator: (req) => req.[1], skip: (req) => req.[2] === '[3]' });
Drag options to blanks, or click blank then click option'
Aip
Bhostname
C127.0.0.1
Durl
Attempts:
3 left
💡 Hint
Common Mistakes
Using req.hostname, which is the requested hostname from the Host header, not the client IP.
Checking req.url instead of IP for skipping.