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

probejs

v1.0.1

Published

Probe endpoints for expected responses and take action if needed

Downloads

3

Readme

probejs

Probe endpoints for expected responses and take action if needed

Build Status

Introduction

It's often necessary to probe HTTP endpoints to ensure services are available or to build health or dependency checking frameworks.

In these types of checks the following scenarios are common:

  • pass - the request returns a valid response
  • fail - the request returns an invalid response
  • error - something else went wrong

A probe is a simple, configurable, event-emitting object designed with this in mind. It handles building and sending requests to endpoints at specified intervals, expects given responses and emits events which can be listened to in order to take action based on the scenarios above.

Installation

npm install --save probejs

Usage

const Probe = require('probe');

// create a new probe providing any required config
const probe = new Probe({
  endpoint: 'http://mydomain:1234/path/to/probe', // the endpoint to probe
  interval: 30,                                   // how often to send a request (in seconds)
  validResponses: [200]                           // array of responses that we'll consider a 'pass'
});

// create any required event listeners
probe.on('fail', (response) => {
  // take some action e.g. send an alert
});

// start the probe
probe.start();

Config

When creating a new Probe() the constructor expects a config object which supports the following keys:

method

type:        string
required:    false
default:     'GET'

the HTTP request method to use

endpoint

type:        string
required:    true
default:     none

the endpoint to probe

supports HTTP/HTTPS, custom ports, paths and query parameters

auth

type:        object
required:    false
default:     none

support for basic auth & bearer tokens

Object expects the following keys:

  • username string (required with password, not valid with bearer)
  • password string (required with username, not valid with bearer)
  • bearer string (not valid with username or password)

headers

type:        object
required:    false
default:     none

custom headers to add to the requests

body

type:        any
required:    false
default:     none

a request body to send e.g. in POST requests

validResponses

type:        array
required:    false
default:     [200]

an array of responses that will be considered a pass

any response not in this array will be considered a fail

interval

type:        int
required:    false
default:     30

the interval in seconds between sending requests

requests continue to be sent until probe.stop() is called

setting this to 0 is equivalent to sending a single request followed by probe.stop()

timeout

type:        int
required:    false
default:     10

the timeout in seconds to wait for a request to complete

note that if the underlying TCP connection cannot be established, the OS-wide TCP connection timeout will overrule the timeout option

Events

The following events can be listened to:

  • start - emitted when probe.start() is called
  • stop - emitted when probe.stop() is called
  • error - emitted when an error occurred trying to send the request
  • complete - emitted at the end of every request, regardless of 'error', 'pass' or 'fail'
  • pass - emitted when the status code of the response was in the validResponses array of the probe config
  • fail - emitted when the status code of the response was NOT in the validResponses array in the probe config