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

fast-osmpbf-js

v0.2.3

Published

Node.js bindings for the fast-osmpbf Rust library

Downloads

297

Readme

fast-osmpbf-js

A library for reading OpenStreetMap files (*.osm.pbf). It is using NodeJS bindings for the high-performance Rust library fast-osmpbf.

npm

Benchmarks

  • CPU: Intel(R) Core(TM) i5-9600K CPU @ 3.70GHz
  • Memory: 16GB
  • OS: Linux (Ubuntu)
  • Dataset: germany-latest.osm.pbf (~4.6GB)
Hyperfine was used to benchmark with 10 runs each.
What you see here is the mean time of these 10 runs.
All problems were run using parallelization if the library offered a way to do it.

| Problem | fast-osmpbf-js | osm-pbf-parser | osm-read | |-----------------|----------------|----------------|----------| | Count ways | 18.10 s | 330.57 s | 523.80 s | | Count addresses | 30.04 s | 359.06 s | 603.33 s |

Examples

  1. Count ways. Since we dont need tags here and we know we only need ways, we apply a tag filter and an element filter beforehand, which basicly avoids sending any tag elements, nodes and relations from Rust to NodeJS. This speeds up computation significantly.
import { JsElementBlock, OsmReader, getNodeIds, getRelationMembers, getTags } from "fast-osmpbf-js"

const reader = new OsmReader("./scripts/osm-data/germany-latest.osm.pbf")
const relevantTags: string[] = []
const relevantElements: JsElementFilter = {
    nodes: false,
    ways: true,
    relations: false,
}
const stream = reader.streamBlocks(relevantElements, relevantTags)

async function main() {
    let totalItems = 0
    let block: JsElementBlock | null = null
    while ((block = await stream.next()) !== null) {
      const { ids } = block
      totalItems += ids.length
    }

    return totalItems
}
  1. Count elements that have full addresses. Since we know which tags we need here, we apply a tag filter and speed up computation here as well.
import { JsElementBlock, OsmReader, getTags } from "fast-osmpbf-js"

const reader = new OsmReader("./scripts/osm-data/germany-latest.osm.pbf")
const relevantTags = ["addr:city", "addr:postcode", "addr:street", "addr:housenumber"]
const stream = reader.streamBlocks(null, relevantTags)

async function main() {
    let totalItems = 0
    let block: JsElementBlock | null = null
    while ((block = await stream.next()) !== null) {
        const { ids } = block
        const blockLength = ids.length

        for (let i = 0; i < blockLength; i++) {
            const tags = getTags(block, i)
            if (tags.length === relevantTags.length) {
                totalItems++
            }
        }
    }

    return totalItems
}

Structure

The stream gives you a JsElementBlock object to work with. It is basicly a collection of elements (Node, Way or Relation). Most of the information can be read from that. Though sometimes its still encoded for performance reasons, so you need to call one of my helper functions that decodes it.

Using the 2 filters like described in the examples above also can help with performance (and filtering).

export interface JsElementBlock {
  ids: BigInt64Array
  elementType: string // Node, Way or Relation
  nodeIds?: [BigInt64Array, Uint32Array] // encoded, dont use, instead use the getNodeIds function
  latitudes?: Float64Array
  longitudes?: Float64Array
  relationMembers?: [BigInt64Array, Uint8Array, Int32Array, Uint32Array] // encoded, dont use, instead use the getRelationMembers function
  denseTags?: [Uint32Array, Uint32Array, Uint32Array] // encoded, dont use, instead use getTags function
  tags?: [Uint32Array, Uint32Array, Uint32Array] // encoded, dont use, instead use getTags function
  stringTable: Array<string> // probably irrelevant for you, needed for functions to decode encoded data
}

License

This project is licensed under

  • Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  • MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)