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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@andreasnicolaou/overpass-client

v1.3.1

Published

A wrapper for the Overpass API to query OpenStreetMap data.

Readme

OverpassClient - Overpass API Wrapper for OpenStreetMap

Overview

OverpassClient is designed to simplify interaction with the Overpass API, used for querying OpenStreetMap (OSM) data. This wrapper provides an easy-to-use interface for retrieving geographic objects like nodes, ways, and relations while handling common issues such as retries, timeouts, and network failures.

TypeScript GitHub contributors License: MIT GitHub Actions Workflow Status npm version

ESLint Prettier Jest Maintenance GitHub issues codecov

GitHub stars

Downloads

Why?

Interacting with the Overpass API directly can be complex due to common issues like network failures, timeouts, and data size concerns. This wrapper addresses those issues by:

  • Automatic Retries: The client automatically retries failed requests with exponential backoff and Jitter.
  • Network Resilience: It reduces downtime caused by intermittent network issues or server limitations.
  • Error Handling: Gracefully handles Overpass-specific errors, retries, and timeouts, including a custom error class for different error scenarios.

This is ideal for developers who want to interact with OSM data without worrying about low-level request handling and retries.

Features

  • Axios Integration: Uses Axios for making HTTP requests, providing flexibility and familiarity.
  • Automatic Retries with Exponential Backoff and Jitter: Built-in retry logic that progressively delays retries with exponential backoff and jitter to avoid overwhelming the server.
  • Observables: Handles asynchronous operations efficiently, with easy composition and transformation of the data flow.
  • Node, Way & Relation Support: Supports querying node, way and relation data, enabling more accurate searches.
  • Caching: Caches responses to optimize performance for repeated queries, using LRU cache.
  • Flexible Querying: Easily query elements by ID, bounding box, or radius with customizable tag filters.

How It Solves Common Problems

  1. Retries and Exponential Backoff:

    • If a request fails, the client automatically retries it with an exponentially increasing delay, including jitter between attempts, ensuring the server isn't overwhelmed.
    • This approach significantly improves reliability, especially when dealing with intermittent issues.
  2. Handling Network and Server Failures:

    • The use of Observables, retry logic, and error handling ensures that transient failures (such as network glitches, rate limiting, or API downtime) don't lead to repeated failures, providing a smoother experience for users.
  3. Simplified API:

    • The library abstracts away complex HTTP request handling and error management, allowing developers to focus on higher-level application logic rather than worrying about the specifics of interacting with the Overpass API.

Installation

npm install @andreasnicolaou/overpass-client

Usage

Importing the Library

import { OverpassClient } from '@andreasnicolaou/overpass-client';

Initialize the Library

this.overpassClient = new OverpassClient();

Query a specific element by ID

this.overpassClient.getElement('way', 452).subscribe((response) => {
  console.log(response);
});

Query elements within a bounding box

const tags = { amenity: ['cafe', 'restaurant'] };
const bbox: [number, number, number, number] = [48.85, 2.29, 48.87, 2.35]; // [minLat, minLon, maxLat, maxLon]
this.overpassClient.getElementsByBoundingBox(tags, bbox).subscribe((response) => {
  console.log(response);
});

Query elements within a radius from a center point

const lat = 48.85;
const lon = 2.35;
const radius = 500;
this.overpassClient.getElementsByRadius(tags, lat, lon, radius).subscribe((response) => {
  console.log(response);
});

API

| Method | Description | Parameters | | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | clearCache() | Clear the LRU cache entirely. | None | | getElement(type: ElementType, id: number, outputFormat: string = 'out;') | Fetches a specific element (node, way, or relation) by its ID. | - type: The type of element ('node', 'way', 'relation').- id: The ID of the element.- outputFormat: The Overpass QL output format (default: 'out;'). | | getElementsByBoundingBox(tags: Record<string, string[]>, bbox: [number, number, number, number], elements: ElementType[] = ['node', 'way', 'relation'], outputFormat: string = 'out center;') | Fetches elements with specified tags within a given bounding box. | - tags: A dictionary of tag types and their possible values.- bbox: A bounding box in the format [minLat, minLon, maxLat, maxLon].- elements: The element types to include in the query (default: 'node', 'way', 'relation').- outputFormat: The Overpass QL output format (default: 'out center;'). | | getElementsByRadius(tags: Record<string, string[]>, lat: number, lon: number, radius: number, elements: ElementType[] = ['node', 'way', 'relation'], outputFormat: string = 'out center;') | Fetches elements with specified tags within a given radius from a point. | - tags: A dictionary of tag types and their possible values.- lat: Latitude of the center point.- lon: Longitude of the center point.- radius: Search radius in meters.- elements: The element types to include in the query (default: 'node', 'way', 'relation').- outputFormat: The Overpass QL output format (default: 'out center;'). |

References

Contributing

Contributions are welcome! If you encounter issues or have ideas to enhance the library, feel free to submit an issue or pull request.