UNPKG

bodhi-node-profiler

Version:

A lightweight, zero-configuration performance profiler for Node.js applications with real-time dashboard

35 lines (29 loc) 894 B
import express from 'express'; import path from 'path'; import { BodhiProfiler } from '../index'; export class Dashboard { private app: express.Application; private profiler: BodhiProfiler; constructor(profiler: BodhiProfiler) { this.profiler = profiler; this.app = express(); this.setupRoutes(); } private setupRoutes() { // Serve static files this.app.use(express.static(path.join(__dirname, 'public'))); // API endpoints this.app.get('/api/metrics', (req, res) => { res.json(this.profiler.getMetrics()); }); // Serve the dashboard HTML this.app.get('/', (req, res) => { res.sendFile(path.join(__dirname, 'public', 'index.html')); }); } public start(port: number) { this.app.listen(port, () => { console.log(`Dashboard running at http://localhost:${port}`); }); } }