• Stars
    star
    123
  • Rank 290,145 (Top 6 %)
  • Language
    JavaScript
  • Created almost 8 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This module adds [Server-Timing](https://www.w3.org/TR/server-timing/) to response headers, see [example](https://server-timing.now.sh/) and open chrome dev tool

server-timing

Build Status Coverage Status

This module adds Server-Timing to response headers. Example is here and open chrome devtool network tab.

You can use this as a express module / basic http function.

Install

$ npm install server-timing -S

Usage

const express = require('express');
const serverTiming = require('server-timing');

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

app.use((req, res, next) => {
  res.startTime('file', 'File IO metric');
  setTimeout(() => {
    res.endTime('file');
  }, 100);
  next();
});
app.use((req, res, next) => {
  // you can see test end time response
  res.startTime('test', 'forget to call endTime');
  next();
});
app.use((req, res, next) => {
  // All timings should be in milliseconds (s). See issue #9 (https://github.com/yosuke-furukawa/server-timing/issues/9).
  res.setMetric('db', 100.0, 'Database metric');
  res.setMetric('api', 200.0, 'HTTP/API metric');
  res.setMetric('cache', 300.0, 'cache metric');
  next();
});
app.use((req, res, next) => {
  res.send('hello');
});

Conditionally enabled

const express = require('express');
const serverTiming = require('server-timing');

const app = express();
app.use(serverTiming({
  // Only send metrics if query parameter `debug` is set to `true`
  enabled: (req, res) => req.query.debug === 'true'
}));

API

constructor(options)

  • options.name: string, default total, name for the timing item
  • options.description: string, default Total Response Time, explanation for the timing item
  • options.total: boolean, default true, add total response time
  • options.enabled: boolean | function, default true, enable server timing header. If a function is passed, it will be called with two arguments, request and response, and should return a boolean.
  • options.autoEnd: boolean, default true automatically endTime is called if timer is not finished.
  • options.precision: number, default +Infinity, number of decimals to use for timings.

Result

image

More Repositories

1

tower-of-babel

Tower of babel is tour of babel
JavaScript
603
star
2

json5

JSON5 implemented by golang
Go
149
star
3

okrabyte

OCR library pure JavaScript (using Ocrad.js)
JavaScript
129
star
4

httpstat

httpstat node implementation
JavaScript
119
star
5

react-nl2br

Newlines to <br /> for React
JavaScript
78
star
6

eater

EAsy Test runnER
JavaScript
78
star
7

node-jsonnet

jsonnet wrapper for Node.js
JavaScript
77
star
8

stubcell

Stubcell is simple stub module
JavaScript
72
star
9

electronica

Electron workshop application
JavaScript
49
star
10

koa-livereload

livereload script appender for Koa
JavaScript
45
star
11

colo

simplest colorize module for Node.js
JavaScript
45
star
12

iojs-new-features

iojs v3.0 released.
JavaScript
39
star
13

socket.io-go-emitter

socket.io-emitter golang implementation
Go
38
star
14

smile-face-detector

Smile face detect library using opencv
JavaScript
35
star
15

golang-study

golang勉強用の資料です
Go
32
star
16

early-hints

JavaScript
23
star
17

nodeslide

node.jsで実現しているスライドとリアルタイムに付箋を貼るシステムです。プレゼン中、シャイな日本人の方でも気軽にツッコミをいれられるように。
JavaScript
19
star
18

umlaut

UML Previewer on electron
CSS
15
star
19

execsyncs

execSync for node v0.10 and v0.11.
C++
15
star
20

hookin

npm install or bower install if package.json changed, when git pull
JavaScript
13
star
21

language-jsx

I already unpublished this module `apm uninstall language-jsx`
CoffeeScript
13
star
22

TokyoNodeFestival2014

東京Node学園祭2014リポジトリ
12
star
23

must-call

example.on('end', mustCall(() => {})); Check the callback function is called.
JavaScript
10
star
24

grunt-jsx

jsx task runner for grunt
JavaScript
10
star
25

wt

wt - watch then
Go
10
star
26

awesome-sonots

awesomeなsonotsを集める所です。
10
star
27

programming-go-study

Programming Go 研修用リポジトリ
Go
7
star
28

angular-koa

CSS
7
star
29

yeomania

JavaScript
7
star
30

atom-tiqav

tiqav client for atom
CoffeeScript
7
star
31

babababel

try to use React, Fetch, Browserify, Babel, LevelDB
JavaScript
6
star
32

dstatwatcher

dstat watch app.
JavaScript
6
star
33

babel_tutorial

babel tutorial
JavaScript
6
star
34

impress.io

impress.io = socket.io + impress.js
JavaScript
6
star
35

generator-tmlib

JavaScript
6
star
36

go-socket.io-test

JavaScript
6
star
37

chat-example

HTML
5
star
38

goquery_sample

Go
5
star
39

gulp-stubcell

stub server for gulp
JavaScript
5
star
40

modern-grunt-sample

JavaScript
4
star
41

esmodules_on_node

4
star
42

gitnpm

npm wrapper for libraries not published to npm, but uploaded on git
JavaScript
4
star
43

active-cache-babel-register

babel register to improve performance and use cache actively
JavaScript
4
star
44

early-hints-demo

HTML
3
star
45

software_design_2016

Node.js Web開発
JavaScript
3
star
46

leets

Rust
3
star
47

primus-sample

JavaScript
3
star
48

smile_shot

Detect Smiles and send smiles to slack and gcloud
JavaScript
3
star
49

sse_stream

Server Sent Event Stream for Node.js
JavaScript
3
star
50

react-twemojify

React Component using twemoji parser, support webcomponents ( amp-img etc).
TypeScript
3
star
51

http2-express-demo

HTML
2
star
52

nodeschool-live-coding-demo

JavaScript
2
star
53

momoclo-slider

momoclo-slider
CoffeeScript
2
star
54

Make10

Scala
2
star
55

worker-babel-demo

JavaScript
2
star
56

socket.io-video

JavaScript
2
star
57

nhk_api.js

NHK client for javascript
JavaScript
2
star
58

jrapper

jrapper detects japanese rhymes in input text. '後始末するアノニマス' => '後始末', 'アノニマス'
JavaScript
2
star
59

grunt-execsyncs

execsync grunt option, this plugin can be used in bath v0.10 and v0.11
JavaScript
1
star
60

dotfiles

1
star
61

tuppari-de-chat

tuppari-de-chat
JavaScript
1
star
62

nodeslide4dotcloud

JavaScript
1
star
63

assert-stream

assertStream.expect({ foo: 'bar' }); res.pipe(assertStream);
JavaScript
1
star
64

ubuntu-koa-hello

JavaScript
1
star
65

plz-port

JavaScript
1
star
66

is-redirectable-url

JavaScript
1
star
67

uv_http_server

C
1
star
68

tryit2

TypeScript
1
star
69

espower-traceur-demo

JavaScript
1
star
70

hello-wasm

JavaScript
1
star
71

NANSample

C++
1
star
72

goweb-sample

CSS
1
star
73

hostbyname

gethostbyname for node.js
JavaScript
1
star
74

phaser-demo

JavaScript
1
star
75

kawasima

JavaScript
1
star
76

jsx_test_tutorial

JavaScript
1
star
77

okrabyte_aws_lamdba_demo

JavaScript
1
star
78

event-recommender

event-recommender
JavaScript
1
star
79

homebrew-json5

Ruby
1
star
80

docker-nodebrew

nodebrew repository for docker
Shell
1
star
81

gdd11jp

For Google DevDays
1
star
82

json5x

JSON5 for JSX
JavaScript
1
star
83

check_v8

JavaScript
1
star
84

grunt-stubcell

JavaScript
1
star
85

gulp-stubcell-example

JavaScript
1
star
86

gulp-execsyncs

JavaScript
1
star
87

momoclo-weather

momoclo-weather
JavaScript
1
star
88

generator-express-socketio

yeoman-generator, creates express and socket.io environment
JavaScript
1
star
89

funmix

FunMix can insert sentences the beginning and the end of each function.
JavaScript
1
star