Skip to content

Instantly share code, notes, and snippets.

@slutske22
Last active December 26, 2021 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slutske22/cfa048cf0c6d88a15c74909f921332e9 to your computer and use it in GitHub Desktop.
Save slutske22/cfa048cf0c6d88a15c74909f921332e9 to your computer and use it in GitHub Desktop.
Simple express app, with profiler
import express from 'express';
import { ... } from './utils'
import Profiler from './Profiler'
// Create a profiler
const profiler = new Profiler({
active: !!process.env.PROFILER,
title: new Date.getTime(),
outputDir: process.env.OUTPUT_DIR
});
// Set up app ...
// Set up routes ...
router.get('/api/simple', (req, res) => {
profiler.start();
const result = simpleCalculation();
res.on('finish', () => {
profiler.finish();
});
res.json(result);
});
router.get('/api/complex', (req, res) => {
profiler.start();
const result = complexCalculation();
res.on('finish', () => {
profiler.finish();
});
res.json(result);
});
// Start server ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment