knockat
TypeScript icon, indicating that this package has built-in type declarations

4.0.101 • Public • Published

knockat

knockat waits until a host is reachable.

Status

Category Status
Version npm
Dependencies David
Dev dependencies David
Build GitHub Actions
License GitHub

Installation

$ npm install knockat

Quick start

First you need to add a reference to knockat in your application:

const { knock } = require('knockat');

If you use TypeScript, use the following code instead:

import { knock } from 'knockat';

Then, call its at function and provide the host as well as the port you want to knock at:

await knock.at('localhost', 3000);

Once the host is reachable, the at function returns. If the host is not reachable permanently, it throws an exception.

Changing the number of retries

If you want to use a different number of retries you basically have two options. You can either set a new default value or set a value for a specific request.

To set a new default value set the retries property:

knock.retries = 100;

If you only want to set this value for a specific request, provide an options object with a retries property:

await knock.at('localhost', 3000, { retries: 100 });

Understanding the algorithm

When you run knockat, it uses the following algorithm to detect whether the given host is reachable:

  • If the host is reachable, the module returns immediately.
  • If the host is not reachable, knockat retries to reach the host every two seconds.
  • If the host is not reachable within 60 retries, knockat fails.

Running quality assurance

To run quality assurance for this module use roboter:

$ npx roboter

Readme

Keywords

Package Sidebar

Install

npm i knockat

Weekly Downloads

19

Version

4.0.101

License

MIT

Unpacked Size

40.3 kB

Total Files

12

Last publish

Collaborators

  • thenativeweb-admin
  • goloroden