axiscloud-sdk
v1.0.3
Published
Express middleware for per-IP rate limiting and request logs batching with GeoIP lookup.
Downloads
50
Maintainers
Readme
AxisCloud SDK (Rate Limiting + Request Logs)
A small library that provides rate limiting + request logs batching as an Express middleware.
Works with:
- ESM (
import) - CommonJS (
require) - JavaScript + TypeScript (types included)
The package name in package.json is: axiscloud-sdk.
How It Works
- Rate limiting: Per IP using
node-cache. When limit exceeded → 429 Too Many Requests. - Logging: Captures
userAgent,ip,path,country. Logs are buffered and sent in batches when they reach 30 entries. - Country: Resolved via
GeoLite2-Country.mmdb(optional). If missing, country =UNKNOWN. - Backend endpoint:
POST http://localhost:3000/CreateLog(hardcoded for now).
Requirements
- Node.js (recommended 18+)
- Express (this library exposes a middleware)
GeoLite2-Country.mmdbis optional. If it is not found, the library will set country toUNKNOWN.
Installation
npm i axiscloud-sdkNote: the library depends on maxmind + node-cache. HTTP is done via built-in fetch.
Quick Start
- Install the package:
npm i axiscloud-sdk- Add this to your
package.jsonscripts:
{
"scripts": {
"setup:geo": "axiscloud-geo-download",
"start": "npm run setup:geo && node server.js"
}
}- Create
server.js:
import express from "express";
import { Logs } from "axiscloud-sdk";
const app = express();
app.use(express.json());
// Logs(apiKey, maxRequests, windowSeconds)
app.use(Logs("YOUR_API_KEY", 100, 60));
app.get("/test", (req, res) => {
res.json({ message: "OK" });
});
app.listen(3001, () => console.log("Server running on port 3001"));- Run:
npm startThat's it! The database will be downloaded automatically and your server will start.
GeoLite2 Database (Country Detection)
Optional: If you don’t set this up, country will be
UNKNOWN.
Manual setup (if you don’t use the script above)
Run this in your project root:
axiscloud-geo-downloadThis downloads GeoLite2-Country.mmdb into your project.
Alternative: Use your own file
If you already have the file, set the path:
Environment variable:
set GEOLITE2_COUNTRY_DB_PATH=C:\path\to\GeoLite2-Country.mmdb
node server.jsFrom code:
import { setGeoDBPath } from "axiscloud-sdk";
setGeoDBPath("C:/path/to/GeoLite2-Country.mmdb");API
Logs(apiKey, maxRequests, windowSeconds)- apiKey (string): Sent with logs to the backend.
- maxRequests (number): Max requests per IP within the window.
- windowSeconds (number): Time window in seconds.
Response when rate limited
{
"message": "To Many Requests"
}Log Format (Backend)
When the buffer reaches 30 entries, logs are sent to:
POST http://localhost:3000/CreateLog
Body:
{
"sentLogs": [
{
"userAgent": "Mozilla/5.0...",
"ip": "192.168.1.1",
"path": "/api/test",
"country": "EG"
}
],
"apiKey": "YOUR_API_KEY"
}Notes
- If the GeoLite2 DB file is missing, the library does not crash—country simply becomes
UNKNOWN. - Backend URL is currently hardcoded to
localhost:3000. Want it configurable? Let me know. - Works with both ESM (
import) and CommonJS (require).
Development (If you’re contributing)
npm run buildOutputs:
dist/(ESM)dist-cjs/(CommonJS)
