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

@varve/worldbank-api

v0.2.0

Published

An isomorphic, Zod-validated TypeScript client for the World Bank Indicators API.

Downloads

45

Readme

@varve/worldbank-api

An isomorphic, Zod-validated TypeScript client for the World Bank Indicators API.

Works in Node.js 18+ and modern browsers. The client exposes countries, indicators, sources, topics, indicator observations, and graph-friendly metadata for natural-language query systems.

Installation

npm install @varve/worldbank-api zod

zod is a required peer dependency.

Quick start

import { WorldBankClient } from '@varve/worldbank-api';

const client = new WorldBankClient();

const population = await client.getIndicatorData('USA', 'SP.POP.TOTL', {
  date: '2020:2024',
});

const graph = await client.getIndicatorGraphMetadata('SP.POP.TOTL', ['USA', 'CAN'], {
  date: '2020:2024',
});

console.log(population.items);
console.log(graph.indicator);
console.log(graph.countries);
console.log(graph.observations);

Configuration

const client = new WorldBankClient({
  baseUrl: 'https://api.worldbank.org/v2',
  maxRetries: 2, // accepted for compatibility; retries are handled by callers
  timeoutMs: 30_000,
});

The client performs one timeout-bound HTTP request per method call. Non-2xx responses expose status, and Retry-After is parsed as retryAfterMs when present.

API reference

Countries

const countries = await client.getCountries({ perPage: 100, page: 1 });
const usa = await client.getCountry('USA');
const allCountries = await client.getAllCountries();

Indicators

const indicators = await client.getIndicators({ perPage: 100, page: 1 });
const population = await client.getIndicator('SP.POP.TOTL');

// Filter indicator catalogue by source or topic
const wdiIndicators = await client.getIndicators({ source: 2, perPage: 100 });
const povertyIndicators = await client.getIndicators({ topic: 11, perPage: 100 });

Sources and topics

const sources = await client.getSources();
const topics = await client.getTopics();

Observations

const data = await client.getIndicatorData(['USA', 'CAN'], 'SP.POP.TOTL', {
  date: '2020:2024',
  perPage: 100,
});

Graph metadata

World Bank data naturally maps to an indicator -> country -> period graph.

const graph = await client.getIndicatorGraphMetadata('SP.POP.TOTL', ['USA', 'CAN'], {
  date: '2020:2024',
});

// Indicator node
graph.indicator;

// Country nodes
graph.countries;

// Observation edges/facts
graph.observations;

Example graph shape:

(:Indicator {id})-[:OBSERVED_IN]->(:Country {id})
(:Observation {period, value})-[:FOR_INDICATOR]->(:Indicator {id})
(:Observation {period, value})-[:FOR_COUNTRY]->(:Country {id})

Official docs

  • Indicators API documentation: https://datahelpdesk.worldbank.org/knowledgebase/articles/889392
  • Indicator API queries: https://datahelpdesk.worldbank.org/knowledgebase/articles/898599-indicator-api-queries
  • API basic call structures: https://datahelpdesk.worldbank.org/knowledgebase/articles/898581-api-basic-call-structures

Error handling

All non-2xx responses throw a WorldBankApiError. World Bank JSON error payloads throw WorldBankResponseError.

import { WorldBankApiError, WorldBankResponseError } from '@varve/worldbank-api';

try {
  await client.getIndicator('missing');
} catch (err) {
  if (err instanceof WorldBankApiError || err instanceof WorldBankResponseError) {
    console.error(err.status);
    console.error(err.retryAfterMs);
    console.error(err.url);
    console.error(err.body);
  }
}