paint-brush
[Express.js] Measuring performance of HTTP Requestby@peterchang_82818
3,158 reads
3,158 reads

[Express.js] Measuring performance of HTTP Request

by August 15th, 2017
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

<code class="markup--code markup--p-code">express-watcher</code> is a middleware of monitoring Express router, it helps to observe information of R<strong>esponse Time</strong>, <strong>RAM, heap memory </strong>and <strong>CPU</strong>.
featured image - [Express.js] Measuring performance of HTTP Request
 HackerNoon profile picture

express-watcher is a middleware of monitoring Express router, it helps to observe information of Response Time, RAM, heap memory and CPU.






During the time of developing Isomorphic Application(React-Redux-ServerRendering), tracking the issue of performance become harder and harder, because performance could be affected by many factors : — Express server performance — API — Component Design(React) — Algorithm — Browser performance

It is a tool that helps me find out performance issue during development stage(NOT PRODUCTION!!!).

Install

$ npm install --save express-watcher

Usage

To print every request

var resourceMonitorMiddleware = require('express-watcher').resourceMonitorMiddleware

// example without callback function

app.use(resourceMonitorMiddleware)

To get monitoring data from every request

var resourceMonitorMiddlewareCB = require('express-watcher').resourceMonitorMiddlewareCB

// example with callback function

app.use(function(req, res, next){




resourceMonitorMiddlewareCB(req, res, next, function(diffJson){console.log(' diffJson : ', diffJson)})})

1- Monitoring each response

Return object as a callback:

{ diffRss: 0.0078125,  diffHeapTotal: 0,  diffHeapUsed: 0.012725830078125,  diffExternal: 0,  diffCpu: 0.000427 }

And auto print:

2- Monitoring all time high information

All time high information is printed when closing (CRT+c) the node process

And auto print:

Reference

https://www.npmjs.com/package/js-meter

https://www.npmjs.com/package/express-watcher