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 🙏

© 2024 – Pkg Stats / Ryan Hefner

http-cache-agent

v1.6.8

Published

HTTP(S) Cache Agent. Compatible with http-proxy-agent, https-proxy-agent, proxy-agent

Downloads

15

Readme

File based HTTP & HTTPS Cache agent

Compatible with http-proxy-agent, https-proxy-agent and proxy-agent.

Installation

npm install --save http-cache-agent

Changelog

2022-04-14

  • FIX BUG SSL Connections
  • FIX BUG if the process exited before the cache file was written
  • Change to Named pipe (no port using more)
  • Added 'http-cache-agent.error' event to socket and request

Usage JavaScript:

const CacheAgent = require('http-cache-agent');
const https = require('https');

// Change path (default is temp)
CacheAgent.filepath = '/usr/local/tmp';

Usage TypeScript:

import * as CacheAgent from 'http-cache-agent';
import https from "https";

// Change path (default is temp)
CacheAgent.filepath = '/usr/local/tmp';

Get content

var ca = CacheAgent.https(); // OR CacheAgent.auto()
var req = https.request(
   'https://www.google.de/manifest?pwa=webhp',
   {agent: ca},
   function (res) {
      var data = '';
      res.on('data', function (chunk) {
         data += chunk
      });

      res.on('end', function () {
         console.info(data);
      });
   }
);

res.on('end', function () {
   console.info(data);
});

req.on('error', function(err) {
    console.error(error);
});

req.end();

Custom socket settings

// rejectUnauthorized: false -> ignore certificate errors
var ca = CacheAgent.https({rejectUnauthorized: false});
var req = https.request(
   'https://www.google.de/manifest?pwa=webhp',
   {agent: ca},
   function (res) {
      var data = '';
      res.on('data', function (chunk) {
         data += chunk
      });

      res.on('end', function () {
         console.info(data);
      });
   }
);

res.on('end', function () {
   console.info(data);
});

req.on('error', function(err) {
    console.error(error);
});

req.end();

Download

var fs = require('fs');
var ca = CacheAgent.auto();
var req = https.get(
   'https://www.google.de/favicon.ico',
   {agent: ca},
   function (res) {
      var stream = fs.createWriteStream('test.ico');
      res.pipe(stream);
   }
)
req.on('error', error => {
   console.error(error)
});

req.end();

With http-proxy-agent

var ProxyAgent = require('https-proxy-agent');
var pa = new ProxyAgent('http://localhost:8118');
var ca = CacheAgent.https(null, pa);

var req = https.request(
   'https://www.google.de/favicon.ico',
   {agent: ca},
   function (res) {
      var data = '';
      res.on('data', function (chunk) {
         data += chunk
      });

      res.on('end', function () {
         console.info(data);
      });
   }
)

req.on('error', error => {
   console.error(error)
});

req.end();

With proxy-agent

var ProxyAgent = require('proxy-agent');
var pa = new ProxyAgent('http://localhost:8118');

var ca = CacheAgent.auto(null, pa);
var req = https.request(
   'https://www.google.de/favicon.ico',
   {agent: ca},
   function (res) {
      var data = '';
      res.on('data', function (chunk) {
         data += chunk
      });

      res.on('end', function () {
         console.info(data);
      });
   }
)
req.on('error', error => {
   console.error(error)
});

req.end();
/**/

Get request

var ca = CacheAgent.https();
var req = https.get(
   'https://www.google.de/favicon.ico',
   {agent: ca},
   function(res) {
      console.log('STATUS: ' + res.statusCode);
      console.log('HEADERS: ' + JSON.stringify(res.headers));

      // Buffer the body entirely for processing as a whole.
      var bodyChunks = [];
      res.on('data', function(chunk) {
         // You can process streamed parts here...
         bodyChunks.push(chunk);
      }).on('end', function() {
         var body = Buffer.concat(bodyChunks);
         console.log('BODY: ' + body);
         // ...and/or process the entire body here.
      })
   }
);

req.on('error', function(e) {
   console.log('ERROR: ' + e.message);
});

Reset cache (set expires date to 1970-01-01T00:00:00)

CacheAgent.reset(function (err) {
   console.error(err);
});

Cleanup cache files (remove expired files)

CacheAgent.cleanup(function (err) {
   console.error(err);
});

Get all cache files

CacheAgent.getCacheFiles(function (err, files) {
   if (err) console.error(err);
   console.info(files);
});