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

check-cert-expiration

v3.1.0

Published

query an SSL/TLS server and report its certificate's expiration date

Downloads

765

Readme

check-cert-expiration

Queries an SSL/TLS server and reports when its certificate expires.

Installation

npm install --global check-cert-expiration # for the command line utility
npm install --save check-cert-expiration # for the library function

Command Line Interface

The check-cert-expiration script accepts 1 or more URLs as command line arguments and prints the results.

One optional command line argument is supported:

  • --days-left N exit with status code 1 if N is greater than or equal to daysLeft. Useful for warning about certificates expiring soon.

Examples

Happy path (return code is 0):

$ check-cert-expiration tomcort.com github.com
host=tomcort.com port=443 valid_to=2018-03-09T10:34:20.000Z daysLeft=89
host=github.com port=443 valid_to=2018-05-17T12:00:00.000Z daysLeft=159

$ check-cert-expiration --days-left 14 tomcort.com
host=tomcort.com port=443 valid_to=2020-05-16T17:38:41.000Z daysLeft=37

Error path (return code is 1):

$ check-cert-expiration does-not-exist.example.com
{ CHECK_CERT_EXPIRATION_COMM: getaddrinfo ENOTFOUND does-not-exist.example.com does-not-exist.example.com:443
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:56:26)
  errno: 'ENOTFOUND',
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'does-not-exist.example.com',
  host: 'does-not-exist.example.com',
  port: 443,
  name: 'CHECK_CERT_EXPIRATION_COMM' }

$ check-cert-expiration --days-left 42 tomcort.com
{ CHECK_CERT_EXPIRATION_DAYS_LEFT: daysLeft is less than or equal to the --days-left command line option
    at process.argv.forEach (/Users/thomasc/repos/check-cert-expiration/bin/check-cert-expiration:27:25)
    at process._tickCallback (internal/process/next_tick.js:68:7)
name: 'CHECK_CERT_EXPIRATION_DAYS_LEFT',
host: 'tomcort.com',
port: 443,
valid_to: '2020-05-16T17:38:41.000Z',
daysLeft: 37,
warnDaysLeft: 42 }

API

checkCertExpiration(targetUrl)

Parameters:

  • targetUrl - a server URL (e.g. https://www.tomcort.com/) or hostname (e.g. tomcort.com).

Return Value:

  • result object with the following properties:
    • host - hostname of the host checked.
    • port - TCP port number of the host checked,
    • valid_to - ISO8601 timestamp string.
    • daysLeft - how many days left until the certificate expires.

Errors:

Errors with the following values of err.name may occur:

  • CHECK_CERT_EXPIRATION_URL_PARSE - when a URL parse error is encountered.
  • CHECK_CERT_EXPIRATION_BAD_PROTOCOL - when the protocol portion of the URL is not https:
  • CHECK_CERT_EXPIRATION_COMM - when there is some type of communications error.

Examples

'use strict';

const checkCertExpiration = require('check-cert-expiration');

(async function () {
    try {
        const { daysLeft, host, port } = await checkCertExpiration('tomcort.com');
        console.log(`${daysLeft} days until the certificate expires for ${host}:${port}`);
        process.exit(0);
    } catch (err) {
        console.error(`${err.name}:${err.message}`);
        process.exit(1);
    }
})();

Testing

npm test

License

See LICENSE.md