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 🙏

© 2026 – Pkg Stats / Ryan Hefner

node-consumer-pact-interceptor

v2.1.1

Published

A means to intercept outgoing requests for the purpose of validating consumer pacts

Readme

Node Consumer Pact interceptor

This is a pure nodejs implementation of the PACT system of mocking and testing system integration points. It is presently in an Alpha state and you should expect some bugs. Be sure to read the caveats below.

Quickstart

See the test/test.js for the fastest way to get started.

Workflow:

(This assumes understanding of - Consumer driven contracts - The PACT v2 specification)

  1. Create pact JSON spec
  2. Create a setState function to pass to the interceptor, the setState function typically send a request to the api under test.
  3. Request will be intercepted as outgoing HTTP requests
  4. Verify the response(s) returned from the interceptor.
  5. Publish pact to broker
Why?

There is a JS DSL for creating pacts which is already compatible with the Pact v2 Spec. However, this requires the use of a ruby server with which to create assertions with.

We found that it was difficult to induct new developers into using this system and the incidental complexity barrier (often compounded by CI servers and docker-containers) was such that this became a real pain-point.

How does it work

The interceptor is just wrapping the excellent MITM library which is catching outgoing HTTP requests at the NodeJS core level and allowing responses to be injected.

From a high-level, the interceptor waits for requests the URL it's watching and, once it receives them, it will try verify this against the PACT specification. If it fails to do so, it will return an assertion error, if there is no assertion failures it will respond as per the PACT specification.

Caveats:
  • As yet this does not fully implement Pact V2. At the time of writing I have been unable to fully meet the requirements of nested type-matching.

  • Outgoing HTTP or socket requests which are not part of the pact test are going to be blocked. This is unfortunate and less than ideal. I have not yet found a way to use MITM's API to allow HTTP requests on a per-url basis.