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-jail

v0.0.5

Published

Express middleware which add malicious actors into a Fail2Ban jail

Readme

express-jail

Express middleware which add malicious actors into a Fail2Ban jail.

Notes:

  • This NPM requires fail2ban at version 0.11.1 or later to be installed and running to work correctly.
  • This module does include a testkit but, due to the way that localhost blocking works on Linux, you will need to use an external facing IP to test it
var port = 8080;
var express = require('express');
var expressJail = require('express-jail');

app = express();
app.use(expressJail({
	// Options, if any
}));

// Route setup
app.use('/api/foo', (req, res) => res.send({string:'Foo!'}));
server = app.listen(port);

API

expressJail(options) - Main Middleware

The main middleware factory function of the module.

Called as (options) where options is an object which can override the defaults.

Returns an @momsfriendlydevco/eventer EventEmitter(-like) instance which emits the following:

| Event | Emitted as | Description | |------------|------------------------|------------------------------------------------------------------------------------------------------------------------------------------------| | ban | (ip, req?, res?) | Emitted before the ban cycle concludes can return an async function which could eventually return boolean false which will prevent the ban | | banned | (ip, req?, res?) | Emitted after the ban cycle concludes | | unban | (ip) | Emitted when calling expressJail.unban(ip), can return an (eventual) boolean false to abort | | unbanned | (ip) | Emitted when expressJail.unban(ip) concluded |

All emitters can optionally return async Promisables which will be waited on.

expressJail.defaults

The default options structure. Can be overridden in each middleware init stage as needed.

| Option | Type | Default | Description | |----------------|-----------------|------------|---------------------------------------------------------------------| | paths | Array<String> | See notes | List of path components to consider malicious | | responseCode | Number | 404 | Initial response code to send before blocking | | clientBinary | Array<Sring> | See notes | Prefix exec paths to access fail2ban-client | | jail | String | "www" | Jail name to use within F2B to collect the ban list | | minVersion | String | "0.11.1" | Minimum Semver version of F2B to work with, set to falsy to disable |

Notes:

  • paths are pre-populated from a standard list of malicious scans. If you have any to add please file a PR
  • clientBinary is set to ['/usr/bin/sudo', '/usr/bin/fail2ban-client'] by default. Each argument part should be its own part of the array to be correctly escaped
  • jail is created before launch if it does not already exist

expressJailInstance.ban(ip)

Can be called manually to ban an IP address.

Returns a Promise which will resolve when the operation has completed.

expressJailInstance.unban(ip)

Can be called manually to unban an IP address.

Returns a Promise which will resolve when the operation has completed.

expressJailInstance.bans()

Returns a promise which will resolve to a collection of all existing bans in the form {ip: String, from: Date, time: Number, to: Date}.

expressJailInstance.hasBan(ip)

Convenience wrapper for expressJailInstance.bans() which queries a specific IP address. Returns a promise which will resolve to a boolean if the provided IP is in the ban list.

expressJailInstance.setup()

Setup and configure the Fail2Ban ruleset. This function is automatically run on initialization. Returns a promise which will resolve when the operation has completed.