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

parrot-js

v0.2.2

Published

Transparently hijack and redirect an application's HTTP requests

Downloads

21

Readme

parrot.js

parrot.js captures outbound HTTP and HTTPS traffic, from a node.js application, and redirects it to a server of your choosing. This is useful for performing blackbox testing on an application which would normally require communication with external servers in order to function. The inspiration for parrotjs came from nock.

Usage

To install,

$ npm install parrot-js

At the entrypoint of your application, put this one-liner:

// Only hijack outbound requests in a testing scenario
if (...)
	require("parrot-js").Hijack({ "Host": "localhost", "Port": 1234 });

Any outbound HTTP/HTTPS calls made after this point will not reach their intended destination, but will be redirected instead to http://localhost:1234 with their paths, querystrings and request bodies intact. This, in conjunction with impostor, enables the author of the application to write tests which don't rely on state held across an HTTP API boundary.

The intercepted traffic has an added header, x-parrot-intended-host, indicating the host to which the traffic was originally addressed.

Documentation

parrot.js only has one method:

require("parrot-js").Hijack(Options)

Options is an object with

  • Host: required string, the host to which HTTP and HTTPS requests should be redirected.
  • Port: required integer, the port to which requests should be redirected.
  • Quiet: optional boolean (default false), suppress logging of requests.

Configuration

Beyond specifying the host and port of the interceptor, parrot.js can be configured without code changes via the following optional environment variables:

  • PARROT_MODE the behavior for handling requests, either INTERCEPT to intercept and forward to a server under your control (the default), or PASSTHROUGH to allow all requests through to their intended destinations.
  • PARROT_HOST_EXCEPTIONS a comma-delimited string, listing hosts that should do the opposite of the chosen mode.

For example,

$ PARROT_HOST_EXCEPTIONS=facebook.com node index.js

will intercept traffic bound for google.com and most other hosts, but it will allow traffic through to facebook.com.

On the other hand,

$ PARROT_MODE=PASSTHROUGH PARROT_HOST_EXCEPTIONS=facebook.com,twitter.com node index.js

will allow traffic through to google.com and most other hosts, but it will intercept traffic bound for facebook.com or twitter.com.

How does it work?

parrot.js works by overriding the request method of the node.js core http and https modules. Any outbound HTTP/HTTPS requests made by your application (including indirectly, through a third party module) eventually use the core modules, so parrot.js captures it all.