0.1.1 • Published 4 years ago

@byu-oit/express-profiler-middleware v0.1.1

Weekly downloads
1
License
Apache-2.0
Repository
github
Last release
4 years ago

Express Profiler Middleware

An Express middleware function for profiling client requests using the v8 profiler (See v8-profiler-next).

Usage Example

const express = require('express')
const profiler = require('@byu-oit/express-profiler-middleware')

const app = express()

app.use(profiler.middleware((req, profile) => {
  const fileName = `${Date.now().toString()}-${req.method}${req.path.split('/').join('-')}.cpuprofile`
  profile.export((error, result) => fs.writeFileSync(fileName, result))
}))

app.get('/xhealth', (req, res) => {
  setTimeout(() => res.sendStatus(200), 250)
})

let port = process.env.PORT || 8080
app.listen(port, () => console.log(`Server listening on port ${port}`))