Registry / data / osm-pbf-parser

osm-pbf-parser

JSON →
library2.3.0jsnpmunverified

osm-pbf-parser is a Node.js library designed for streaming parsing of OpenStreetMap Protocol Buffer (PBF) files. It processes binary PBF data, converting it into a stream of JavaScript objects representing OSM nodes, ways, and relations. The current stable version is 2.3.0. This library is designed for handling large `.pbf` files efficiently by processing them in a streaming fashion, avoiding the need to load the entire file into memory. It further differentiates itself by exposing `BlobParser` and `BlobEncoder` components, which allow for distributing binary work units and facilitating parallel processing of PBF data blobs, a feature useful for high-performance data extraction and transformation workflows. Due to its age (last updated in 2021) and CommonJS-only nature, it should be considered for projects that can tolerate an unmaintained dependency or require its specific streaming and parallel processing features for older Node.js environments.

npm install osm-pbf-parser
INSTALL
IMPORT
SIG · OSM-PBF-PARSER
O
osm-pbf-parser
datajavascriptv2.3.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parseOSM
const parseOSM = require('osm-pbf-parser');
import parseOSM from 'osm-pbf-parser';
This library is exclusively CommonJS. Direct ESM imports will result in a runtime error.
BlobParser
const { BlobParser } = require('osm-pbf-parser');
import { BlobParser } from 'osm-pbf-parser';
Access BlobParser as a named property from the CommonJS export for parallel processing capabilities.
BlobEncoder
const { BlobEncoder } = require('osm-pbf-parser');
import { BlobEncoder } from 'osm-pbf-parser';
Access BlobEncoder as a named property from the CommonJS export for encoding binary work units.

Demonstrates streaming parsing of an OpenStreetMap PBF file, logging the type, ID, and tags of each item (node, way, or relation) to the console.

const fs = require('fs'); const through = require('through2'); const parseOSM = require('osm-pbf-parser'); // To run, save a .pbf file (e.g., 'denmark-latest.osm.pbf') // and execute with: node your_parser.js denmark-latest.osm.pbf const filePath = process.argv[2]; if (!filePath) { console.error('Usage: node parser.js <path_to_osm.pbf_file>'); process.exit(1); } const osmStream = parseOSM(); fs.createReadStream(filePath) .pipe(osmStream) .pipe(through.obj(function (items, enc, next) { items.forEach(function (item) { // Each item is an OSM node, way, or relation object console.log(`Type: ${item.type}, ID: ${item.id}, Tags:`, item.tags); }); next(); })) .on('finish', () => { console.log('Finished parsing PBF file.'); }) .on('error', (err) => { console.error('Error during parsing:', err); });
Debug
Known issues
gotchaThe `osm-pbf-parser` library is no longer actively maintained, with the last commit dating back to October 2021. This implies a lack of ongoing support for bug fixes, security vulnerabilities, or compatibility with newer Node.js versions or OSM PBF specification changes.
fix
For new projects, consider actively maintained alternatives. If using this library, be prepared to fork and maintain the codebase yourself for critical updates or compatibility issues.
affects: >=2.0.0
breakingThis library is exclusively CommonJS (CJS). Attempting to use `import` syntax in an ES module (ESM) environment will result in a `ReferenceError: require is not defined` or similar import errors.
fix
Ensure your project or file uses CommonJS (`require()`) for importing `osm-pbf-parser`. For modern ESM projects, you might need to use a CJS wrapper or consider alternative streaming PBF parsers that support ESM.
affects: >=2.0.0
gotchaThe parsing relies on the underlying `pbf` library and the specific PBF schema it expects. If the OpenStreetMap PBF specification changes significantly in the future, this library might not be able to correctly parse newer PBF files without updates to its dependencies or source, which are unlikely given its abandoned status.
fix
Regularly verify compatibility with your target OSM PBF file versions. If parsing issues arise with newer files, manual adjustments or migration to a different parser may be necessary.
affects: >=2.0.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use `require()` in an ES module (ESM) context, or trying to `import` this CJS-only library.
fix
Ensure your Node.js project or file is configured for CommonJS, or refactor to use `require()` within a CJS context. For modern ESM projects, consider a dynamic `import()` or an alternative parser.
TypeError: parseOSM is not a function
Incorrectly importing the `parseOSM` function, typically by using `import parseOSM from 'osm-pbf-parser'` instead of `const parseOSM = require('osm-pbf-parser')`.
fix
Use the correct CommonJS `require` syntax: `const parseOSM = require('osm-pbf-parser');`.
Error: PBF parse error: unknown field X at offset Y
The PBF file being parsed might be corrupted, or its schema (e.g., a newer version of OSM PBF) contains fields not recognized by the parser's underlying `pbf` dependency.
fix
Verify the integrity of your PBF file. If the file is valid, consider if the PBF schema has evolved beyond what this unmaintained library supports. Upgrading the `pbf` dependency (if compatible) or using a different, actively maintained parser might be required.
Upgrade
Version history
2.3.0latest on npm
Audit
Dependencies
pbfrequiredCore dependency for parsing Protocol Buffer data.
varintrequiredUsed for reading and writing variable-length integers in the PBF format.
through2requiredUsed internally for creating transform streams.
Agent activity
32 hits · last 30 days
node
22
Amazon
1
Bingbot
1
Resources
osm-pbf-parser — npm install osm-pbf-parser · libregistry