A heartbeat monitor.

Usage no npm install needed!

<script type="module">
  import primeHeartbeat from '';



A heartbeat monitor.

This module is based off jasonkuhrt-heartbeat but differes in that the heartbeat will continue to call the flatlinefunction unless there has been at least 1 call to the heartbeat.

Its designed to monitor data streams on an open connection for some form of state. Where a connection being open isn't enough to determine if something is healthy.


npm install jasonkuhrt-heartbeat


var tcp = require('net');
var heartbeat = require('prime-heartbeat');

var thump = heartbeat(onFlatLine,500);

var socket = new net.Socket();

socket.on('data', thump);

function onFlatLine() {
  console.log('Remote device isnt sending any data');
> npm start
... (Socket opens, streams in data. After some period the remote device misbehaves)
Remote device isnt sending any data


Heartbeat → .setHeartbeat

.setHeartbeat(onFlatline, intervalMs)

Heartbeat h; Int i;  :: ( -> ), i -> h

Returns a heartbeat instance. A heartbeat instance is a function. Invoke it to keep the heartbeat going. The identifier is typically thump (see guide).

  • onFlatline is invoked and will continue to invoke when/if thump is not invoked during an interval until cleared.

  • intervalMs sets the time between thump checks.


Heartbeat a :: a -> undefined

Destroy a heartbeat instance. Analagous to clearInterval/clearTimeout.

Only use clearHeartbeat if you need to abort a heartbeat before onFlatline.