mnglab
Version:
Dead simple REST micro-framework with modular routing, API key, rate limiting, full HTTP response handling, dev tools, JSON DB, file helpers, endpoint stats, and professional developer experience.
35 lines (25 loc) • 777 B
JavaScript
const path = require('path');
const fs = require('fs');
const statsFile = path.join(process.cwd(), '.mnglab.stats.json');
if (!fs.existsSync(statsFile)) {
fs.writeFileSync(statsFile, JSON.stringify({ total: 0, endpoints: {} }, null, 2));
}
function loadStats() {
const raw = fs.readFileSync(statsFile, 'utf-8');
return JSON.parse(raw);
}
function saveStats(data) {
fs.writeFileSync(statsFile, JSON.stringify(data, null, 2));
}
function countHit(method, endpoint) {
const stats = loadStats();
stats.total += 1;
const key = `${method.toUpperCase()} ${endpoint}`;
if (!stats.endpoints[key]) stats.endpoints[key] = 0;
stats.endpoints[key] += 1;
saveStats(stats);
}
function getStats() {
return loadStats();
}
module.exports = { countHit, getStats };