npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

express-slas

v1.1.1

Published

SLA's handler for Express.JS

Readme

Build Status Dependencies Status Codacy Badge Node

NPM

express-slas

SLA's (Service Level Agreement) handler for Express.JS

What does it do?

Set a max time for your API and this middleware will report back if the response time goes over it. It does not cancel the request, it just logs an error by default (using console.error).

0 dependencies, all native, all fast.

You can pass a callback to perform custom actions such as sending notifications to slack / hipchat / JIRA tickets. This callback will be executed asynchronously, you don't have to be worried about it delaying the response even more.

As per Express nature, this middleware will evaluate the time between the time when the request comest to it and then when the headers are set.

Note Remember that you can, and maybe you you should, apply this middleware to those routes that actually require to meet certain SLA (like get by id operations). That is not implmented in the library intentionally since express already supports that functionality out of the box (for instance http://stackoverflow.com/questions/15877342/nodejs-express-apply-session-middleware-to-some-routes).

Usage

Install it:

npm install -S express-slas

Declare it and use it

var slas = require("express-slas");
// Assuming 'app' is an express object
app.use(slas());

Note Don't forget that for more accurate results this middleware should be loaded before all other middleware (except you really require to load something before i.e. security reasons).

Full example:

'use strict';
var express = require("express"),
    app = express(),
    slas = require("express-slas");
    
var monitor = function(t){
    // Notify monitoring system
};

// Setting a SLA of 100ms, disabling default error message and passing a callback
app.use( slas({sla: 100, logError: false, cb: monitor}) );

app.get("/", function(req, res){
    res.send("hello world");
});

app.listen(8080, function(){
   console.log("app started"); 
});

Options

Options are passed in the initialization as an object with the following properties:

sla (time in milliseconds, default 1000ms, optional)

Time in milliseconds.

logError (boolean, default true, optional)

Logs an error message to the console using console.error

cb (callback, optional)

Custom callback that will be executed asynchronously after the response is sent to the client. This callback is only executed if the SLA is not met. It passes the time spent as an argument.

disableFor (time in seconds, default 10, optional)

Defines a pause time after a SLA is not met, otherwise the library could cause a log flood with all the messages making the situation even worse. By default, it waits for 10 seconds before starting to check again.