toddg toddg - 1 year ago 56
Node.js Question

See how long a Heroku request has run for

Is it possible to determine how long a Heroku Node.js request has run for?

At the end of every Heroku request, I get the following line written to my log:

2016-08-22T22:00:05.410367+00:00 heroku[router]: at=info method=POST path="xxx" host=xxx request_id=xxx fwd="" dyno=web.1 connect=1ms service=2759ms status=200 bytes=669

var tells me how long the request took to run (as detailed here). Is it possible to access this variable while the request is running?

Answer Source

Sure, though measuring request times has nothing specifically to do with Heroku.

Just add some sort of timer to your request handlers. For example, in express, you can dynamically see how long a request has taken (so far) by doing something like:

const express = require('express');
const app = express();
  .use((req, res, next) => {
    req.start =;
  .get('/', (req, res) => {
    console.log( - req.start);
  .listen(process.env.PORT || 3000, () => {

By recording the time at which a request starts, you can always later compute how long that request has taken.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download