heart-ping

A simple light-weight Typescript module for pinging HTTP services at set intervals to provide a heartbeat.

Usage no npm install needed!

<script type="module">
  import heartPing from 'https://cdn.skypack.dev/heart-ping';
</script>

README

Heart Ping

License Current Version npm Bundle Size

A simple light-weight Typescript module for pinging HTTP services at set intervals to provide a heartbeat.

Installation

yarn add heart-ping

Usage

import HeartPing from 'heart-ping';

const heartPing = new HeartPing();
heartPing.setBeatInterval(10_000);
heartPing.setBeatTimeout(30_000);
heartPing.setOnTimeout(() => {
  console.log('The ping request to www.google.com has timed out!');
});
heartPing.start(
  'www.google.com', // or using https, e.g.: 'https://www.google.com'
  80,
  (time) => {
    console.log(`Successfully pinged www.google.com! It took ${time} milliseconds.`);
  },
  () => {
    console.log('Failed to ping www.google.com!');
  },
);