Socket
Book a DemoInstallSign in
Socket

express-chrono

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-chrono

Simple hrtime chronometer with Expressjs middleware. Request timer, process timer.

1.0.2
latest
Source
npmnpm
Version published
Weekly downloads
299
29.44%
Maintainers
1
Weekly downloads
 
Created
Source

express-chrono

Simple process.hrtime chronometer with Expressjs middleware. Request timer, process timer.


const express = require("express");

const app = express();

const chrono = require("express-chrono")({ header: true });

app.use(chrono.middleware.start);

app.get("/", (req, res, next)=> {
  res.send("Hello World");
  next();
});

app.use(chrono.middleware.stop);

app.use((req, res, next) => {
  console.log(req.chrono);
});

app.listen(3000);

Options

header - boolean or string of the header name. Defaults to false. If true the default header is X-Response-Time

format

  • s - seconds, default, e.g 1.029382120s
  • ms - milliseconds, e.g 1029.382120ms

suffix - boolean, default false; include the second or millisecond suffix

Module

const chrono = require("express-chrono")(options);

chrono.middleware

  • start - express start middleware, put this before the request. Creates a field chrono on req of type Chronometer
  • stop - express stop middleware, put this after the request. Stops the timer on req.chrono. You can stop the timer at any time from req.chrono.stop() or look at the current accumulated time req.chrono.parse()

class Chronometer

constructor(options) - options, same as above, except header

Properties

diff - returns start time hrtime diff of now or diff since stopped. hrtime - hrtime at start or now if not started.

Methods

start() - starts the chronometer at that moment

stop() - stops the chronometer at that moment

parse(format, suffix) - returns the parsed time so far or since stopped. format and suffix are optional, inheritted from constructor, if provided they will override Chronometer instance options.

toJSON() - returns parse()

toString() - returns parse()

valueOf() - returns current diff or diff since stopped in seconds fixed decimal number with percision of 9.


const Chronometer = require("express-chrono").Chronometer;
 
 let chrono = new Chronometer({ format: "ms", suffix: true });
 
 chrono.start();
 
 setTimeout(() => {
   chrono.stop();
   
   console.log(chrono); // 100ms
 }, 100);

Keywords

timer

FAQs

Package last updated on 10 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.