{"id":29509792,"url":"https://github.com/faizan-devs/api-rate-limiter-nodejs","last_synced_at":"2026-04-04T21:33:30.191Z","repository":{"id":304820179,"uuid":"1020101253","full_name":"faizan-devs/api-rate-limiter-nodejs","owner":"faizan-devs","description":"A complete Node.js API Rate Limiter system with hashed API keys, plan-based usage limits, warning emails on 90% and 100% quota usage, daily CSV reports, and scheduled cron jobs for automation.","archived":false,"fork":false,"pushed_at":"2025-07-15T11:03:41.000Z","size":28,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-09T07:36:44.612Z","etag":null,"topics":["api","automate","backend","exec","express","javascript","mongodb","mongoose","nodecron","nodejs","nodemailer","nodemon"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/faizan-devs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-15T10:43:54.000Z","updated_at":"2025-07-15T11:17:05.000Z","dependencies_parsed_at":"2025-07-16T03:09:17.554Z","dependency_job_id":"2e374e38-9c3e-463f-b013-4c2007d876f1","html_url":"https://github.com/faizan-devs/api-rate-limiter-nodejs","commit_stats":null,"previous_names":["faizan-devs/api-rate-limiter-nodejs"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/faizan-devs/api-rate-limiter-nodejs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faizan-devs%2Fapi-rate-limiter-nodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faizan-devs%2Fapi-rate-limiter-nodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faizan-devs%2Fapi-rate-limiter-nodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faizan-devs%2Fapi-rate-limiter-nodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/faizan-devs","download_url":"https://codeload.github.com/faizan-devs/api-rate-limiter-nodejs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faizan-devs%2Fapi-rate-limiter-nodejs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31415110,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-04T20:09:54.854Z","status":"ssl_error","status_checked_at":"2026-04-04T20:09:44.350Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","automate","backend","exec","express","javascript","mongodb","mongoose","nodecron","nodejs","nodemailer","nodemon"],"created_at":"2025-07-16T07:25:23.131Z","updated_at":"2026-04-04T21:33:30.167Z","avatar_url":"https://github.com/faizan-devs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# API Rate Limiter System (with API Key, Daily Limits \u0026 Email Notifications)\n\nThis project implements a robust **API Rate Limiting System** that restricts API usage based on user subscription plans (`basic`, `pro`, `premium`). It features **API key generation**, **daily usage tracking**, **email alerts at 90% and 100% usage**, and **CSV reporting via cron job**.\n\n---\n\n## 📌 Key Features\n\n- 🔐 **API Key Generation** for each user.\n- 📊 **Daily API Usage Tracking** per user via MongoDB.\n- ⚠️ **Automatic Email Warning** at 90% usage.\n- ⛔ **Limit Reached Email** and block at 100% usage.\n- 📬 **Daily CSV Usage Report** emailed to admin at 8 AM.\n- 🔁 **Usage Reset** every midnight via scheduled cron.\n- 🔁 **API Key Regeneration** (admin only).\n- 🧾 **User Dashboard (Admin Route)** with daily usage summary.\n\n---\n\n## 🧰 Tech Stack\n\n| Layer       | Tech/Tool                 |\n| ----------- | ------------------------- |\n| Backend     | Node.js, Express.js       |\n| Database    | MongoDB (Mongoose ODM)    |\n| Email       | Nodemailer + Gmail SMTP   |\n| Scheduler   | node-cron                 |\n| Data Format | json2csv (CSV generation) |\n| Security    | Hashed API Keys (SHA-256) |\n\n---\n\n## 🧪 API Routes and Usage (Postman Guide)\n\n### 1. Create User (with API Key)\n\n`POST /api/users`\n\n```\n{\n  \"name\": \"Faizan\",\n  \"email\": \"faizan@example.com\",\n  \"plan\": \"basic\"\n}\n```\n\n### 2. Regenerate API Key (Admin)\n\n`PUT /api/admin/users/:id/apikey` \u003cbr\u003e\nResponse will contain a new raw API key (shown once only).\n\n### 3. Rate-Limited Test API Route\n\n`GET /api/data` \u003cbr\u003e\nHeader:\n\n```makefile\nx-api-key: YOUR_API_KEY_HERE\n```\n\n### 4. Admin Dashboard\n\n`GET /api/admin/dashboard` \u003cbr\u003e\n📊 Returns all users with today’s usage.\n\n### 5. Update User Details\n\n`PUT /api/users/:id`\n\n```json\n{\n  \"name\": \"Updated Name\",\n  \"email\": \"newemail@example.com\"\n}\n```\n\n`scripts/dailyReport.js` \u003cbr\u003e\nRuns every day at 8 AM (via separate cron or manually) to: \u003cbr\u003e\n📤 Generate CSV of daily usage \u003cbr\u003e\n📧 Email it to ADMIN_EMAIL defined in .env\n\n### .env Configuration\n\nCreate a `.env` file:\n\n```ini\nPORT=3000\nMONGO_URI=mongodb+srv://your-db-uri\nEMAIL_USER=youremail@gmail.com\nEMAIL_PASS=yourapppassword\nADMIN_EMAIL=admin@example.com\n```\n\n---\n\n### Future Implementations\n\n- 🔒 JWT-based authentication + role-based access.\n\n- 💰 Stripe integration for upgrading plans.\n\n- 📈 Analytics dashboard with charts (React/Next.js).\n\n- 📬 Admin alerts for users hitting limits.\n\n- 🧪 API testing dashboard (Postman clone UI).\n\n- 📁 Download logs \u0026 reports from dashboard.\n\n## Scripts\n\n`npm run dev` – Start dev server (with nodemon)\n\n`node index.js` – Run usage reset cron\n\n`node scripts/dailyReport.js` – Send daily CSV\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaizan-devs%2Fapi-rate-limiter-nodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffaizan-devs%2Fapi-rate-limiter-nodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaizan-devs%2Fapi-rate-limiter-nodejs/lists"}