Skip to content

Getting Started

AmirVoid12 edited this page Sep 18, 2026 · 1 revision

Getting Started

Requirements

Requirement Details
Node.js 16 or newer
OS (all protocols except ping) Linux, macOS, Windows
OS (ping / ICMP) Linux only for now
Build tools (only if no prebuilt binary matches) gcc, make, python3

Install

npm install pingflux

The package includes a small native C addon for ICMP. On Linux, node-gyp-build uses a prebuilt binary when one matches your platform. Otherwise it compiles the addon from source during install.

Your first monitor

import { Pingflux } from "pingflux";

const pf = new Pingflux();

pf.watch({ protocol: "https", url: "example.com", interval: 10000 });
pf.watch({ protocol: "tcp",   url: "example.com:443" });
pf.watch({ protocol: "dns",   url: "example.com" });

pf.on("up",          (e) => console.log("UP",    e.target, `${e.latency}ms`));
pf.on("slow",        (e) => console.log("SLOW",  e.target, `${e.latency}ms`));
pf.on("down",        (e) => console.log("DOWN",  e.target));
pf.on("probe_error", (e) => console.log("ERROR", e.target, e.error));

Options

new Pingflux(options?)

Option Type Default Description
threshold number 1000 Latency in ms above which a slow event is emitted
retry number 1 Retries on failure before emitting down or probe_error

pf.watch(target)

Field Type Default Description
protocol Protocol required http, https, tcp, udp, dns, ping
url string required Format depends on the protocol, see Protocols
interval number 5000 Probe interval in ms
threshold number global Per-target override
retry number global Per-target override

watch() returns true when monitoring started, and false if the same protocol + url is already being watched.

Next steps

Clone this wiki locally