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

query-geo-boundary

v1.0.0

Published

Query the boundary of an administrative area from OpenStreetMap Nominatim or Overpass as GeoJSON

Readme

QueryGeoBoundary

A Node.js library to query the geo (administrative area) boundary from OSM nominatim and/or overpass.

Usage

import { queryGeoBoundary } from 'query-geo-boundary';
// CommonJS: const { queryGeoBoundary } = require('query-geo-boundary');

const places = await queryGeoBoundary('Zhucheng, Shandong', { userAgent: 'my-app/1.0 ([email protected])' });
for (const place of places) {
    console.log(place.display_name, place.geojson);
}

The package ships ESM and CommonJS builds with TypeScript declarations. queryGeoBoundary is also the default export; the option and result types are exported as QueryGeoBoundaryOptions and GeoBoundaryPlace.

API

Prototype: queryGeoBoundary(geoName, options)

  • geoName: name of the geo you want to obtain its boundary
  • options: optional.
    • source: 'nominatim' (default, recommended) queries Nominatim once with polygon_geojson. 'overpass' looks the place up on Nominatim, then fetches all matching boundaries from Overpass in one rel(id:...) query. Public Overpass instances are often at capacity: on HTTP 429/5xx, a network error or a 90 s timeout, the next endpoint is tried, and after a failed round over all of them the lookup waits 15 s, then 30 s, before trying again.
    • overpassUrl: Overpass endpoint or endpoints to try in order. Defaults to overpass-api.de, overpass.private.coffee and maps.mail.ru. Point it at your own instance for heavy use, as the public instances ask.
    • userAgent: the User-Agent sent to both services. Defaults to query-geo-boundary/<version> (+https://github.com/tibetty/QueryGeoBoundary). The Nominatim usage policy asks applications to identify themselves, so set this to your app's name and contact.

Return: a promise of the matching OSM relations (GeoBoundaryPlace[]), as Nominatim describes them, with the boundary under geojson. With the nominatim source, geojson is Nominatim's geometry; with overpass, it is the osm2geojson-lite conversion of the relation. A typical result:

[{
    "place_id": 220758967,
    "licence": "Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright",
    "osm_type": "relation",
    "osm_id": 3468769,
    "lat": "35.9957253",
    "lon": "119.4041185",
    "class": "boundary",
    "type": "administrative",
    "display_name": "诸城市, 潍坊市, 山东省, 262200, 中国",
    "boundingbox": ["35.7163774", "36.2834811", "118.9952393", "119.7232973"],
    "geojson": {"type": "Polygon", "coordinates": [[[118.9952393, 36.0120809], "...", [118.9952393, 36.0120809]]]}
}]

Errors: the promise rejects with an Error. HTTP failures name the service and status in the message and set err.status (e.g. 429 when Overpass rate-limits you).

Notice: 'coz it's very common for an administrative uint has the same name with the others, if you want to get the boundary of exactly that place, please supply as much as possible hierarchical adminstrative information in name, e.g., using "Ikeda, Hokkaido" rather than "Ikeda", or you can solve this kind of ambiguity by introducing human interference.

Node.JS Requirement

  • Node.js 22+

Dependency

  • osm2geojson-lite - a regex and map accelerated xml parsing & geojson reconstruction utility, much faster than xmldom, osmtogeojson in combination to convert an OSM XML to geojson

License

MIT