2.0.2 • Published 6 years ago
shipb_miniprofiler v2.0.2
MiniProfiler for Node.js
Node.js implementation of Stack Exchange's MiniProfiler
Demonstration
Visit http://miniprofiler-demo.herokuapp.com for a live demonstration.
Installation
$ npm install miniprofilerYou can hook up your application with any of the following packages are available on npm:
| Name | About | Version |
|---|---|---|
miniprofiler-http | Profile http(s) requests | |
miniprofiler-pg | Profile pg queries | |
miniprofiler-redis | Profile redis calls |
Usage
Simple usage with express.js
server.js
var express = require('express')
, miniprofiler = require('miniprofiler')
, app = express();
app.set('view engine', 'pug');
app.use(miniprofiler.express());
app.get('/', function(req, res) {
req.miniprofiler.step('Step 1', function() {
req.miniprofiler.step('Step 2', function() {
res.render('index');
});
});
});
app.listen(8080);index.pug
doctype html
html
head
title MiniProfiler Node.js Example
body
h1 Home Page
| !{miniprofiler.include()}When visiting localhost:8080, you should see this.

API
miniprofiler.{framework}([options])
Replace {framework} with koa, express or hapi.
This function returns a framework specific middleware that is responsible for initializing MiniProfiler on each request.
options object properties
| Property | Default | Description |
|---|---|---|
| enable | Always returns true | function(req, res) => boolean; this function is used to determine if the profiler should be enabled for the current request |
| authorize | Always returns true | function(req, res) => boolean; this function is used to determine if the current request should be able to see the profiling results |
miniprofiler.{framework}.for([provider])
provider is a call for any of the supported providers listed here.
miniprofiler.configure([options])
options object properties
options.storage examples
InMemoryStorage
miniprofiler.configure({
storage: miniprofiler.storage.InMemoryStorage({ lruCacheOptions });
})Refer to lru-cache documentation for lruCacheOptions.
RedisStorage
miniprofiler.configure({
storage: miniprofiler.storage.RedisStorage(client);
})Where client is an instance of redis.createClient.