Reference
Instance API
resetKey(key)
Resets the rate limiting for a given key. An example use case is to allow users to complete a captcha to reset their rate limit, then call this function.
Example:
import { rateLimit } from 'express-rate-limit'
const limiter = rateLimit({
skip: (req) => req.url === '/reset', // Don't limit the reset url!
// ...
})
app.use(limiter)
app.post('/reset', async (req, res) => {
if (/* Validate that they completed the captcha or whatever */) {
limiter.resetKey(req.ip);
res.send('Rate limit is reset!')
} else {
res.status(400).send("Wrong answer, try again.")
}
})
If you use a custom keyGenerator
, be
sure to replace req.ip
with the correct key.
getKey(key)
Retrieves the hit count and reset time from the store for a given key.
Note: getKey
depends on store support. It works with the MemoryStore and
cluster-memory-store, but may not work with other stores. Calling it will throw
an error if the store does not have a get
method.