Registry / storage / osm-pbf-parser-node

osm-pbf-parser-node

JSON →
library1.1.4jsnpmunverified

Streaming OpenStreetMap PBF parser for Node.js. Version 1.1.4. Parses .osm.pbf files into a readable stream of OSM entities (header, nodes, ways, relations). Built for modern Node (16.13+). Exports an async generator (createOSMStream) and a Transform class (OSMTransform). Supports filtering tags per entity type, raw PBF blocks, and optional metadata. Ships TypeScript definitions.

npm install osm-pbf-parser-node
INSTALL
IMPORT
SIG · OSM-PBF-PARSER-NOD
O
osm-pbf-parser-node
storagejavascriptv1.1.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

createOSMStream
✓ import { createOSMStream } from 'osm-pbf-parser-node'
✗ const { createOSMStream } = require('osm-pbf-parser-node')
ESM-only package; require() will fail. Use dynamic import if needed in CJS: import('osm-pbf-parser-node').then(m => m.createOSMStream(...))
OSMTransform
✓ import { OSMTransform } from 'osm-pbf-parser-node'
✗ import OSMTransform from 'osm-pbf-parser-node'
Named export, not default. Also requires 'node:stream' Transform for piping.
OSMOptions
✓ import type { OSMOptions } from 'osm-pbf-parser-node'
TypeScript only. Use type import for better tree-shaking.

Parses an .osm.pbf file and writes each OSM entity as a JSON line to an output file.

import { createOSMStream } from 'osm-pbf-parser-node'; import { createWriteStream } from 'node:fs'; async function main() { const filePath = 'input.osm.pbf'; const outputPath = 'output.jsonl'; const writeStream = createWriteStream(outputPath, { flags: 'a' }); try { for await (const item of createOSMStream(filePath, { withTags: true, withInfo: false })) { writeStream.write(JSON.stringify(item) + '\n'); } } catch (err) { console.error('Parse error:', err); } finally { writeStream.end(); } console.log('Done'); } main();
Debug
Known issues
breakingE-mail only, no CommonJS support. Node 16.13+ required (nullish coalescing operator used).
fix
Use Node 16.13+; if in CommonJS, use dynamic import: const { createOSMStream } = await import('osm-pbf-parser-node');
affects: >=1.0.0
gotchaDefault options: withInfo=false, withTags=true. Metadata (user, uid, changeset) not included unless explicitly enabled.
fix
Pass { withInfo: true } if you need metadata fields.
affects: *
gotchaFile path must be a local file; no direct URL support (despite npm 'node-fetch' dependency being optional for other use).
fix
Download the .pbf file first, then parse from local path.
affects: >=1.0.0
deprecatedOlder versions (<1.0) had a different API. Check migration if upgrading from 0.x.
fix
Upgrade to 1.x: use createOSMStream instead of older synchronous parse function.
affects: <1.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/osm-pbf-parser-node/index.js from /path/to/script.js not supported.
Package is ESM-only, but script uses require()
fix
Convert to ESM or use dynamic import: const { createOSMStream } = await import('osm-pbf-parser-node');
TypeError: createOSMStream is not a function
Incorrect import (default instead of named)
fix
Use named import: import { createOSMStream } from 'osm-pbf-parser-node';
Error: Cannot find module 'pbf'
Missing dependency pbf (should be installed automatically, but manually cleared)
fix
Run npm install and ensure pbf is in node_modules. If corrupted, delete node_modules and reinstall.
Upgrade
Version history
1.1.4latest on npm
Audit
Dependencies
node-fetchoptionalUsed for HTTP streaming if input is a URL (though not shown in README, dep check may reveal)
Agent activity
14 hits · last 30 days
node
14
Resources
osm-pbf-parser-node — npm install osm-pbf-parser-node · libregistry