Last active
December 26, 2021 21:26
-
-
Save slutske22/cfa048cf0c6d88a15c74909f921332e9 to your computer and use it in GitHub Desktop.
Simple express app, with profiler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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