Registry / database / bson-ext

bson-ext

JSON →
library4.0.3jsnpmunverified

A C++ native addon for BSON serialization/deserialization, used as a faster alternative to the pure JavaScript js-bson library. Version 4.0.3 is the latest stable release, compatible with js-bson v4+ and the MongoDB Node.js driver v4+. The package has irregular release cadence and is now deprecated in favor of the pure JavaScript js-bson library, which eliminates native compilation issues and provides better cross-platform support. It is only for Node.js (not browser) and uses N-API for native bindings.

npm install bson-ext
INSTALL
IMPORT
SIG · BSON-EXT
B
bson-ext
databasejavascriptv4.0.3
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.

BSON
✓ const BSON = require('bson-ext')
✗ import BSON from 'bson-ext'
bson-ext is not ESM-compatible; only CommonJS require works.
Long
✓ const Long = require('bson-ext').Long
✗ const { Long } = require('bson-ext')
Long is a property on the BSON object, not a named export.
ObjectId
✓ const ObjectId = require('bson-ext').ObjectId
✗ const ObjectId = require('bson').ObjectId
ObjectId is exported from bson-ext, not the bson package.

Demonstrates serialization and deserialization using deprecated bson-ext native addon with CommonJS.

const BSON = require('bson-ext'); const Long = BSON.Long; // Create a document with a Long type const doc = { long: Long.fromNumber(100) }; // Serialize to BSON buffer const data = BSON.serialize(doc); console.log('Serialized BSON:', data); // Deserialize back const deserialized = BSON.deserialize(data); console.log('Deserialized:', deserialized);
Debug
Known issues
deprecatedbson-ext is deprecated; use js-bson (the 'bson' package) instead.
fix
Replace 'bson-ext' with 'bson' in package.json and require statements: const BSON = require('bson');
affects: >=4.0.0
breakingv4.0.0+ requires js-bson v4+ and MongoDB driver v4+; incompatible with older versions.
fix
Ensure all dependencies are updated to v4+.
affects: >=4.0.0
gotchabson-ext is a native addon requiring build tools (e.g., python, make) and may fail on some platforms.
fix
Use js-bson which is pure JavaScript and has no native dependencies.
affects: all
gotchaESM imports (import/export) are not supported; only CommonJS require works.
fix
Use require('bson-ext') instead of import.
affects: all
breakingThe token-based serialization options were removed in v4.0.0; only checkKeys, serializeFunctions, ignoreUndefined are supported.
fix
Update serialization options to exclude removed tokens.
affects: >=4.0.0
Errors
Common errors & fixes
Error: The module 'bson-ext' was compiled against a different Node.js version using NODE_MODULE_VERSION 72. This version of Node.js requires NODE_MODULE_VERSION 70.
Native addon compiled for a different Node.js version.
fix
Rebuild bson-ext against your Node.js version: npm rebuild bson-ext or switch to 'bson'.
Module not found: Error: Can't resolve 'bson-ext'
Missing or incorrectly imported package.
fix
Install bson-ext: npm install bson-ext. Use require('bson-ext'), not import.
TypeError: BSON.serialize is not a function
Using default import instead of require, or package not properly required.
fix
Use const BSON = require('bson-ext'); then BSON.serialize(doc).
Error: Cannot find module '../build/Release/bson'
Native addon build artifacts missing or incompatible platform.
fix
Try npm rebuild bson-ext or switch to js-bson (bson package).
Upgrade
Version history
4.0.3latest on npm
Audit
Dependencies
bsonrequiredProvides core BSON types and serialization logic; bson-ext replaces the pure JS implementation with a native addon for performance.
Agent activity
17 hits · last 30 days
node
16
OpenAI (training)
1
Resources
bson-ext — npm install bson-ext · libregistry