[Express.js] Measuring performance of HTTP Request

Written by peterchang_82818 | Published 2017/08/15
Tech Story Tags: javascript | nodejs | react | testing | web-development

TLDRvia the TL;DR App

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


Published by HackerNoon on 2017/08/15