npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

globalping

v0.2.0

Published

The official TS/JS client for the Globalping API

Downloads

20,779

Readme

Globalping Typescript API Client

The official TypeScript client for the Globalping API. Works both in the browser and in node.js.

If you are not familiar with Globalping yet, check out the main Globalping repository first.

Installation

npm i globalping

In client-side applications, you can also import the library directly via jsDelivr CDN.

Usage

The library provides methods for all API operations, as well as types for all parameters. It also exports values for all enum parameters as JS objects, which can be used for client-side validation.

Quick start

Using the package in ESM/CJS applications:

import { Globalping } from 'globalping';

const globalping = new Globalping({
    auth: 'your-globalping-api-token', // Optional.
    // See the Advanced configuration section below for more options.
});

Using the UMD build:

const { Globalping } = window.globalping;
const globalping = new Globalping(/* options */);

Create a measurement

Creates a new measurement with the set parameters. The measurement runs asynchronously, and you can retrieve its current state using getMeasurement() or wait for its final state using awaitMeasurement().

const result = await globalping.createMeasurement({
    type: 'ping',
    target: 'example.com',
});

if (!result.ok) {
    // See the Error handling section below.
}

console.log(result); // => { data: { id: string, probesCount: number }, ... }

Get a measurement

Returns the current state of the measurement.

const result = await globalping.getMeasurement(id);
console.log(result); // => { data: { id: string, status: string, ... }, ... }

Await a measurement

Similar to getMeasurement(), but keeps pooling the API until the measurement is finished, and returns its final state.

const result = await globalping.awaitMeasurement(id);
console.log(result); // => { data: { id: string, status: 'finished', ... }, ... }

List probes

Returns a list of all probes currently online and their metadata, such as location and assigned tags.

const result = await globalping.listProbes();
console.log(result); // => { data: [ { version: string, ... }, ... ], ... }

Get rate limits

Returns rate limits for the current user (if authenticated) or IP address (if not authenticated).

const result = await globalping.getLimits();
console.log(result); // => { data: { rateLimit: { ... }, ... }, ... }

TypeScript convenience methods

There are a few convenience methods for determining more specific response types.

assertHttpStatus() / isHttpStatus()

const result = await globalping.createMeasurement(id);

if (Globalping.isHttpStatus(400, result)) {
    // You can now access parameter validation error details.
}

assertMeasurementType() / isMeasurementType()

const result = await globalping.awaitMeasurement(id);
Globalping.assertMeasurementType('ping', result); // You can now access ping-specific properties on result.data

Error handling

The library offers two ways of handling errors.

throwApiErrors: false (default)

Known API errors, such as parameter validation errors, rate limit errors, etc., are not thrown as exceptions. This allows the library to return precise error types for each method, which means you can access all error details in a type-safe way. You need to check each result before accessing its data.

const result = await globalping.createMeasurement();

// This is sufficient if you only care about success/failure.
if (result.ok) {
    // result.data is the success response, e.g., { id: string, probesCount: number }
} else {
    // result.data can be any of the possible error responses

    if (Globalping.isHttpStatus(400, result)) {
        // You can also access result.data.error.params here which is specific to this status code.
    }
}

Any unexpected errors, such as timeouts, networking errors, etc., are still thrown as exceptions.

throwApiErrors: true

All errors, including known API errors, are thrown as exceptions. You don't have to check result.ok before accessing the data, but the thrown errors only have generic types.

import { ApiError, HttpError } from 'globalping';

try {
    const result = await globalping.createMeasurement();
    console.log(result.data) // => { id: string, probesCount: number }
} catch (e) {
    if (e instanceof ApiError) {
        // Any error with a valid JSON response body.
    } else if (e instanceof HttpError) {
        // Any HTTP error with an invalid response body.
    } else {
        // Any other error.
    }
}

Advanced configuration

There are a few config options available, but all of them are optional:

auth: string

A user authentication token obtained from https://dash.globalping.io or via OAuth (currently available only to official Globalping apps).

userAgent: string

Refers to this library by default. If you build another open-source project based on this library, you should override this value to point to your project instead.

throwApiErrors: boolean

If false (default), known API errors are not thrown as exceptions. See the Error handling section.

timeout: number

A timeout in ms for every HTTP request made by the library. The default value is 30 seconds, and you shouldn't need to change this.

Development

Please refer to CONTRIBUTING.md for more information.