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

cache-proxy-server

v2.0.6

Published

A simple HTTP caching proxy server that forwards requests to localhost:3000 with intelligent in-memory caching

Readme

Cache Server Proxy

A caching proxy server that forwards requests to a target server and caches responses for improved performance.

Overview

This proxy server acts as an intermediary between clients and a target server. It caches responses based on the request method, URL, and body, reducing redundant requests to the target server.

Features

  • 🚀 Request Forwarding: Proxies all HTTP requests to the target server
  • 💾 Smart Caching: Caches responses with unique keys based on request parameters
  • Performance: Returns cached responses instantly for duplicate requests
  • 🔄 All HTTP Methods: Supports GET, POST, PUT, PATCH, and other HTTP methods
  • 📝 Request Logging: Logs cache hits and proxy requests for debugging

Installation

Install as a CLI Tool (Recommended)

npm install -g cache-proxy-server

Then start the server anywhere:

cache-proxy-server

Install from Source

git clone https://github.com/nirtal/cache-server-proxy.git
cd cache-server-proxy
npm install

Usage

CLI Usage (Global Installation)

The proxy server requires two arguments: --from (where the proxy listens) and --target (where requests are forwarded).

cache-proxy-server --from http://localhost:3100 --target http://localhost:3000

Options:

  • --from <url> - URL to run the proxy server on (required)
  • --target <url> - URL to forward requests to (required)
  • -h, --help - Show help message
  • -v, --version - Show version number

Examples:

# Basic usage with default ports
cache-proxy-server --from http://localhost:3100 --target http://localhost:3000

# Use different ports
cache-proxy-server --from http://localhost:8080 --target http://localhost:3000

# Forward to a remote server
cache-proxy-server --from http://0.0.0.0:3100 --target http://api.example.com

# Forward to a different host and port
cache-proxy-server --from http://localhost:4000 --target http://staging-server:8080

Source Usage

If running from source, you can modify the default values in index.js or use the CLI interface:

# Run with default values (http://localhost:3100 -> http://localhost:3000)
npm start

# Or use node directly
node bin/cli.js --from http://localhost:3100 --target http://localhost:3000

Development Mode

For development with auto-reload:

npm run dev

Configuration

The proxy server is configured via command-line arguments:

  • --from <url>: Specifies where the proxy server listens (e.g., http://localhost:3100)
  • --target <url>: Specifies where requests are forwarded (e.g., http://localhost:3000)

Both arguments are required when using the CLI. When running from source without arguments, it uses default values:

  • Default Proxy: http://localhost:3100
  • Default Target: http://localhost:3000

Programmatic Usage

You can also use the proxy server as a module in your own code:

import { createProxyServer } from 'cache-proxy-server';

createProxyServer('http://localhost:3100', 'http://localhost:3000');

How It Works

  1. Request Reception: Client sends a request to the proxy server (configured via --from)
  2. Cache Check: Server generates a unique cache key based on:
    • HTTP method
    • Request URL
    • Request body
  3. Cache Hit: If cached, returns the stored response immediately
  4. Cache Miss: If not cached:
    • Forwards request to target server (configured via --target)
    • Stores response in cache
    • Returns response to client

Cache Key Generation

Cache keys are generated using SHA1 hash of:

{
  method: "GET",
  url: "/api/endpoint",
  body: { ... }
}

Example

Assuming you started the proxy with:

cache-proxy-server --from http://localhost:3100 --target http://localhost:3000

Then make requests:

# First request - proxied to target server
curl http://localhost:3100/api/data

# Second identical request - served from cache
curl http://localhost:3100/api/data

Console output:

[PROXY] GET http://localhost:3000/api/data
[CACHE HIT] GET /api/data

Dependencies

  • express: Web framework for handling HTTP requests
  • node-fetch: HTTP client for forwarding requests
  • crypto: Built-in Node.js module for hash generation

Development Dependencies

  • nodemon: Auto-restart server during development

Client-Side Setup with Requestly

To enable this proxy on client sites, you need to use the Requestly Chrome Extension.

Setup Instructions

  1. Install Requestly

  2. Configure Script Injection

    • Create a new rule in Requestly
    • Set the rule type to "Insert Scripts"
    • Configure the URL condition based on your client application (e.g., URLs containing http://localhost:4200)
    • Add the following script (adjust URLs to match your setup):
<script type="text/javascript">
	  (function() {
	    // Configure these URLs to match your setup
	    const originalTarget = "http://localhost:3000";  // The original API server
	    const proxyUrl = "http://localhost:3100";        // Your proxy server (--from URL)
	
	    // Intercept all fetch requests
	    const originalFetch = window.fetch;
	    window.fetch = async function(resource, config) {
	      if (typeof resource === "string" && resource.startsWith(originalTarget)) {
	        const redirected = resource.replace(originalTarget, proxyUrl);
	        console.log("[Requestly Redirect] fetch →", redirected);
	        return originalFetch(redirected, config);
	      }
	      return originalFetch(resource, config);
	    };
	
	    // Intercept XMLHttpRequests
	    const OriginalXHR = window.XMLHttpRequest;
	    function RedirectedXHR() {
	      const xhr = new OriginalXHR();
	      const originalOpen = xhr.open;
	      xhr.open = function(method, url, ...rest) {
	        if (url && typeof url === "string" && url.startsWith(originalTarget)) {
	          const redirected = url.replace(originalTarget, proxyUrl);
	          console.log("[Requestly Redirect] XHR →", redirected);
	          return originalOpen.call(this, method, redirected, ...rest);
	        }
	        return originalOpen.call(this, method, url, ...rest);
	      };
	      return xhr;
	    }
	    window.XMLHttpRequest = RedirectedXHR;
	
	    // Intercept navigation (window.location etc.)
	    const originalOpen = window.open;
	    window.open = function(url, ...args) {
	      if (url && typeof url === "string" && url.startsWith(originalTarget)) {
	        url = url.replace(originalTarget, proxyUrl);
	        console.log("[Requestly Redirect] window.open →", url);
	      }
	      return originalOpen.call(window, url, ...args);
	    };
	
	    console.log(`✅ Requestly redirect script loaded: ${originalTarget} → ${proxyUrl}`);
	  })();
</script>
  1. How It Works
    • The script intercepts all HTTP requests made from your client application
    • Automatically redirects requests from the original API server to your proxy server
    • Logs all redirected requests in the browser console for debugging
    • Note: Adjust originalTarget and proxyUrl in the script to match your --target and --from URLs

Error Handling

If the target server is unreachable or returns an error, the proxy will return a 502 Bad Gateway status with error details.

License

ISC

Notes

  • Cache is stored in memory and will be cleared when the server restarts
  • All request headers are forwarded to the target server
  • Response headers from the target server are preserved in cached responses