Skip to content

Dev Mode Profiler

The DevModeModule provides a real-time HTTP request profiler for development. It tracks request duration, status codes, headers, and bodies — exposed via a REST API.

Setup

typescript
import { Module, DevModeModule } from 'next-js-backend';

@Module({
  imports: [
    DevModeModule.register({
      enabled: process.env.NODE_ENV !== 'production',
      maxHistory: 200,
    }),
  ],
})
export class AppModule {}

Production Safety

DevModeModule automatically disables itself when enabled: false. It is safe to import unconditionally — no overhead in production.

API Endpoints

EndpointDescription
GET /__dev/requestsList recent requests (newest first)
DELETE /__dev/requestsClear history
GET /__dev/statsAggregated statistics

Sample Response

json
[
  {
    "id": "uuid",
    "method": "POST",
    "url": "/api/users",
    "status": 201,
    "durationMs": 45.2,
    "timestamp": "2024-03-16T10:30:00.000Z",
    "body": { "name": "Alice" }
  }
]

Stats Response

json
{
  "totalRequests": 120,
  "avgDuration": 23.4,
  "errorRate": 2.5,
  "statusCodes": { "200": 100, "404": 15, "500": 5 }
}

Configuration Options

OptionTypeDefaultDescription
enabledbooleanfalseEnable the module
maxHistorynumber100Max requests stored in memory

Memory Safety

Request history is trimmed to maxHistory entries automatically — no unbounded memory growth.

Released under the MIT License.