@epic-js/express-profiler
v0.2.1
Published
Lightweight Express API profiler with route/middleware/async timing
Maintainers
Readme
express-profiler
Lightweight Express API profiler with route, middleware, DB, and external API timing.
Installation
npm i @epic-js/express-profilerUsage
const express = require('express');
const apiProfiler = require('@epic-js/express-profiler');
const app = express();
app.use(expressProfiler());Output
POST /reverseGeoCoding 200 279.9ms// ----- Fast route -----
app.get('/users', async (req, res) => {
const users = await wrapAsync(async () => [{ id: 1, name: 'Alice' }], 'DB', req)();
res.send(users);
});Output
GET /users 200 1.4ms
DB: 0.2msAfter finding the slow routes dig deeper by using the wrapAsync
Usage
const { wrapAsync } = require('@epic-js/express-profiler/wrappers');
// ----- Slow route -----
app.get('/slow', async (req, res) => {
const dbTask = wrapAsync(() => new Promise(r => setTimeout(r, 300)), 'DB', req);
const apiTask = wrapAsync(() => new Promise(r => setTimeout(r, 200)), 'External API', req);
await dbTask();
await apiTask();
res.send('Slow route done');
});GET /slow 200 518.3ms
DB: 309.1ms
External API: 203.9ms// ----- Route with nested async -----
app.get('/nested', async (req, res) => {
await wrapAsync(async () => {
await wrapAsync(() => new Promise(r => setTimeout(r, 100)), 'Inner DB', req)();
}, 'Outer wrapper', req)();
res.send('Nested async done');
});GET /nested 200 111.3ms
Inner DB: 106.6ms
Outer wrapper: 106.6msCLI Usage
express-profiler-cli logs.json