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

https-pool

v1.0.1

Published

A cached pool of https server for domains

Downloads

6

Readme

https-pool

A cached pool of https server for domains.


NPM version Build Status codecov.io NPM downloads

Install

$ npm i https-pool --save

Usage

https-pool is useful for getting https server without worry about forging certificates.

Just pass your CA certificate options into HttpsPool, and get a empty https server pool.

const HttpsPool = require("https-pool");
const fs = require("fs");

const key = fs.readFileSync(path.join(fixtures, "root.key"));
const cert = fs.readFileSync(path.join(fixtures, "root.crt"));

const httpsPool = new HttpsPool({
  key,
  cert,
  commonName: "example",
  countryName: "CN",
  ST: "SH",
  localityName: "SH",
  organizationName: "example.com",
  OU: "example.com"
});

// You can save the cert and key of root CA to let the client trust it.
const { key, cert } = httpsPool.CA;

You can get a https server like this ↓. That's enough for common usage. https-pool will take care of the cache logic, so worrying about your memory is unnecessary.

httpsPool.getServer(
  "www.foo.com",
  (req, res) => {
    // the listener for server.request event
    console.log(req.headers);
    res.send("ok");
  },
  _port => {
    // callback with a random available port
    console.log(typeof _port === "number");
  },
  // timeout for the new https-server
  3000
);

API

Properties

  • httpsPool.CA - return as {key, cert} in the format as pem. (You could trust the key and cert on the your client such as browser)

HttpsPool(options)

It will create a https pool.

  • options
    • option.timeout - https server won't close until secure conntection is established within timeout (default 6000)
    • option.max_servers - max num for https servers the pool cached (default 220)
    • option.key and option.cert- the private key and cert of the root ca which your client trusts or https-pool will create one
    • If you don't pass option.key and option.cert, you need to pass these options:
      • option.commonName - the common name option
      • option.countryName - the country name option
      • option.ST - the ST option
      • option.localityName - the locality name option
      • option.organizationName - the organization name option
      • option.OU - the OU option

HttpsPool#getServer(hostname, listener, callback, timeout)

It will return a https server if available or will create one and cached.

  • hostname - hostname which https server base on
  • listener {Function | Object} - request event listener or Object type with custom event listener
  • callback - callback func with port arg
  • timeout - timeout for https server in ms

HttpsPool#existsServer(hostname)

Tell whether the server basing on the hostname exists

  • hostname - the hostname server base on
  • return {boolean}

HttpsPool#removeServer(hostname)

Remove the server in the cache

  • hostname - the hostname server base on

HttpsPool#free()

Free the https server who has no connections when count > max

HttpsPool#clear()

Clear the https pool forcily

LICENSE

Licensed under the MIT license.