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 🙏

© 2026 – Pkg Stats / Ryan Hefner

periodic-check

v1.0.0

Published

Smart health checking with adaptive intervals. Automatically adjusts check frequency based on system health state.

Downloads

12

Readme

periodic-check

Smart health checking with adaptive intervals. Automatically adjusts check frequency based on system health state.

Features

  • 🎯 Adaptive Intervals - Check more frequently when issues are detected
  • 🔄 Smart State Management - Prevents status flapping with configurable thresholds
  • 📊 Built-in Metrics - Track availability, status history, and trends
  • 🎛 Flexible Configuration - Customize intervals and thresholds for your needs
  • 🪝 Event System - React to status changes and track transitions

Installation

npm i periodic-check

Quick Start

import { PeriodicCheck } from "periodic-check";

// Create a checker with custom intervals (in milliseconds)
const checker = new PeriodicCheck({
	healthy: 30000, // 30s when healthy
	suspect: 5000, // 5s when suspect
	unhealthy: 1000, // 1s when unhealthy
});

// Add status listeners
checker
	.on("healthy", data => console.log("All good!", data.metrics))
	.on("suspect", data => console.log("Warning...", data.metrics))
	.on("unhealthy", data => console.log("System down!", data.metrics));

// Start checking
checker.check(async () => {
	const response = await fetch("https://api.example.com/health");
	return response.status === 200;
});

Configuration

const checker = new PeriodicCheck({
	// Required: Check intervals for each state
	healthy: 30000, // Time between checks when healthy
	suspect: 5000, // Time between checks when suspect
	unhealthy: 1000, // Time between checks when unhealthy

	// Optional: State transition configuration
	maxSuspectCount: 3, // Failed checks before going unhealthy (default: 3)
	minHealthyCount: 2, // Successful checks needed for recovery (default: 2)
});

State Transitions

The checker moves through three states:

  1. HealthySuspect
    • Occurs after first failed check
    • Increases check frequency
  2. SuspectUnhealthy
    • After maxSuspectCount consecutive failures
    • Further increases check frequency
  3. Unhealthy/SuspectHealthy
    • After minHealthyCount consecutive successes
    • Returns to normal check frequency

Events

checker.on("healthy", data => {
	// data = {
	//   status: 'healthy',
	//   metrics: {
	//     availability: 0.98,
	//     statusCounts: { healthy: 45, suspect: 3, unhealthy: 0 },
	//     currentStreak: 10
	//   },
	//   history: [/* recent status changes */]
	// }
});

// Available events:
// - 'healthy'
// - 'suspect'
// - 'unhealthy'
// - 'error'

Metrics

Access health check metrics at any time:

// Get metrics for the last hour
const metrics = checker.getMetrics();

// Get custom time range history
const recentHistory = checker.getRecentHistory(30); // last 30 minutes

Use Cases

API Health Monitoring

const apiChecker = new PeriodicCheck({
	healthy: 60000, // 1 minute
	suspect: 10000, // 10 seconds
	unhealthy: 2000, // 2 seconds
});

apiChecker.check(async () => {
	try {
		const response = await fetch("https://api.example.com/health");
		return response.status === 200;
	} catch {
		return false;
	}
});

Database Connection

const dbChecker = new PeriodicCheck({
	healthy: 30000,
	suspect: 5000,
	unhealthy: 1000,
});

dbChecker.check(async () => {
	try {
		await db.query("SELECT 1");
		return true;
	} catch {
		return false;
	}
});

Resource Monitoring

const memoryChecker = new PeriodicCheck({
	healthy: 15000,
	suspect: 5000,
	unhealthy: 1000,
});

memoryChecker.check(async () => {
	const usage = process.memoryUsage();
	return usage.heapUsed < 1000000000; // 1GB
});

Error Handling

The checker treats any thrown errors as failed checks:

checker
	.on("error", error => console.error("Check failed:", error))
	.check(async () => {
		// Any errors here will trigger the 'error' event
		// and be treated as a failed check
		throw new Error("Connection failed");
	});

Cleanup

Don't forget to stop the checker when done:

// Clean up timers
checker.stop();

License

ISC