Lightweight Express API profiler with route/middleware/async timing
npm install @epic-js/express-profilerLightweight Express API profiler with route, middleware, DB, and external API timing.
bash
npm i @epic-js/express-profiler
`Usage
`js
const express = require('express');
const apiProfiler = require('@epic-js/express-profiler'); const app = express();
app.use(expressProfiler());
`Output
`bash
POST /reverseGeoCoding 200 279.9ms
``js
// ----- Fast route -----
app.get('/users', async (req, res) => {
const users = await wrapAsync(async () => [{ id: 1, name: 'Alice' }], 'DB', req)();
res.send(users);
});
`Output
`bash
GET /users 200 1.4ms
DB: 0.2ms
`After finding the slow routes dig deeper by using the wrapAsync
Usage
`js
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');
});
`
`bash
GET /slow 200 518.3ms
DB: 309.1ms
External API: 203.9ms
`
`js
// ----- 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');
});
`
`bash
GET /nested 200 111.3ms
Inner DB: 106.6ms
Outer wrapper: 106.6ms
`CLI Usage
`
express-profiler-cli logs.json
``