Adding ratelimits and blocks to my API server

I want to implement some sort of API rate-limiting and blocks on my remix of this project like preventing someone from adding a blank URL to the server like this…

## Think the URL is undefined.
https://forked-apps-awake.glitch.me/api/urls/add?url=

…and instead, greet them with a JSON error and block them temporarily for a whole day like this…

{
 "ok": false,
 "description": "You sent us a blank URL and the server blocked your requests temporarily for a whole day.",
 "request_data": {
   "url": null,
   "status": "urlAdd_aborted"
 },
 "apiAccessBlock": {
  "status": "tempbanned",
  "reason": "Sent a blank URL to the API.",
  "expires_on": "24 hours"
 }
}

But the question is what Node.js packages should I use for implementing rate-limits and automated/manual bans and how to implement them?

I think there is a package…a simple search should work.

If you are using express you can use express-rate-limit

1 Like

If I use MemoryStore, does its rate-limited IP addresses on memory will clear on triggering refresh or stopping a project on API?

Yeah it will, I guess

1 Like

So, I want to go to file-based DB instead to guessing how can I connect to a Redis database on my code. How?

I don’t have any experience with Redis specifically, but this project looks like it might be able to walk you through it.

1 Like

@FlantasticDan I am having issues when using Node.js with Redis. When I start on Glitch, only the Redis server is up, not the Express one. Any solution?