vinaysolaskar/rate-limiter-library ? reverse-engineered prompt
Reverse engineered prompt
Build me a small Node.js rate limiting library that I can drop into an API and use right away.
It should support both a token bucket limiter and a sliding window counter, let me rate limit by user id or IP using a key I choose, and work with simple in memory storage by default. I also want an Express middleware helper so I can plug it into an app and customize how the key is picked, what happens when a request gets blocked, and how logging works. If Redis is available, use it, but if it fails, fall back to memory so the app keeps running.
Please include a couple of clear usage examples, basic tests for the main behavior and edge cases, and TypeScript type support if that fits. Keep it clean and easy to extend later, because I may want to add more algorithms or storage options down the road.
Are you gonna build this?
make sure you review the code using coderabbit