1.0.3 • Published 6 years ago

express-served-page-time v1.0.3

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

express-served-page-time

Express middleware that outputs in your view the time used to serve the page.

Installation

via npm:

$   npm install --save express-served-page-time

Get started

Initialize it as a middleware after Express.

const express = require('express');
const pageTimer = require('express-served-page-time');

const app = express();
app.use(pageTimer());

In your view file use the local variable timer to return the value.

p This page was served in #{timer.getTime()} seconds.

The output will be:

<p>This page was served in 0.0215 seconds.</p>

Options

Set time units and decimals. These settings will be forced for all the outputs in the app.

There are seconds, microseconds and nanoseconds. The default settings is seconds with 4 decimals.

app.use(pageTimer({ unit: 'microseconds', decimals: 2 }));

To change the name of the local variable used in the view initialize with the option localName.

app.use(pageTimer({ localName: 'anotherName' }));

And use it like this:

p This page was served in #{anotherName.getTime()} seconds.

License

MIT © Federico Moretti