Lightweight TypeScript wrapper for the check-host.net API.
npm install checkhost-tsimport { checkHttp, getResult } from "checkhost-ts";
const check = await checkHttp("check-host.net", { maxNodes: 1 });
const result = await getResult(check.request_id);
console.log(check.request_id);
console.log(result);Low-level helper for direct API calls.
apiFetch(path: string, params?: Record<string, string | string[]>): Promise<unknown>checkPing(host: string, options?: CheckOptions): Promise<CheckResponse>
checkHttp(host: string, options?: CheckOptions): Promise<CheckResponse>
checkTcp(host: string, options?: CheckOptions): Promise<CheckResponse>
checkDns(host: string, options?: CheckOptions): Promise<CheckResponse>
checkUdp(host: string, options?: CheckOptions): Promise<CheckResponse>CheckOptions:
type CheckOptions = {
maxNodes?: number;
nodes?: string[];
};maxNodes: limits number of checker nodes (max_nodesin API).nodes: explicit node list (sent as repeatednodequery params).
getResult(requestId: string): Promise<CheckResult>
getResultExtended(requestId: string): Promise<ExtendedResult<CheckResult>>requestId is URL-encoded by the library before request execution.
getNodeIPs(): Promise<Record<string, NodeEntry>>
getNodeHosts(): Promise<Record<string, NodeEntry>>Exported core types:
CheckResponseCheckOptionsCheckResultPingResultHttpResultTcpResultDnsResultExtendedResult<T>NodeEntryNodeInfoCheckHostError
The library throws CheckHostError for:
- non-2xx API responses (
statusCodeis HTTP status) - network failures (
statusCodeis0) - non-JSON responses when JSON is expected
import { CheckHostError } from "checkhost-ts";
try {
await checkHttp("check-host.net");
} catch (error) {
if (error instanceof CheckHostError) {
console.error(error.statusCode, error.message);
}
}