Registry / serialization / socket.io-msgpack-parser

socket.io-msgpack-parser

JSON →
library3.0.2jsnpmunverified

This package offers an alternative parser for Socket.IO, utilizing the MessagePack format for efficient binary serialization of data instead of the default JSON-based parser. Its primary goal is to minimize message sizes, which is particularly advantageous for applications with high message throughput, though it results in a slightly larger browser bundle (an additional 7.5 KB minified, 3.0 KB gzipped). The current stable version is 3.0.2, which includes TypeScript definitions. The project maintains close compatibility with Socket.IO's protocol versions, requiring a matching parser version on both the server and client (e.g., parser 3.x with Socket.IO 3.x/4.x). This parser differentiates itself by providing a binary-optimized transport layer, a key contrast to the standard `socket.io-parser` and `socket.io-json-parser`.

npm install socket.io-msgpack-parser
INSTALL
IMPORT
SIG · SOCKET.IO-MSGPACK-
S
socket.io-msgpack-parser
serializationjavascriptv3.0.2
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.

customParser
import customParser from 'socket.io-msgpack-parser';
import { customParser } from 'socket.io-msgpack-parser';
The package exports the parser instance as its default export. For ESM, use a default import. CommonJS `require()` directly resolves to this default export.
customParser (CJS)
const customParser = require('socket.io-msgpack-parser');
For CommonJS environments, the `require` statement directly loads the default exported parser instance.
Parser (Type)
import type { Parser } from 'socket.io-msgpack-parser';
import { Parser } from 'socket.io-msgpack-parser';
To import the TypeScript type definition for the parser, use a type import. The runtime parser instance is the default export, not a named export `Parser`.

Demonstrates how to integrate the MessagePack parser on both the Socket.IO server and client, ensuring consistent message encoding/decoding.

const io = require('socket.io'); const ioc = require('socket.io-client'); const customParser = require('socket.io-msgpack-parser'); const PORT = process.env.PORT || 3000; const server = io(PORT, { parser: customParser }); server.on('connection', (socket) => { console.log('Server: Client connected'); socket.on('hello', () => { console.log('Server: Received hello from client'); socket.emit('world', 'from server'); }); }); const socket = ioc('ws://localhost:' + PORT, { parser: customParser }); socket.on('connect', () => { console.log('Client: Connected'); socket.emit('hello'); }); socket.on('world', (data) => { console.log('Client: Received world:', data); socket.disconnect(); server.close(); }); socket.on('disconnect', () => { console.log('Client: Disconnected'); }); console.log(`Server and client running on port ${PORT}`);
Debug
Known issues
breakingVersion 3.0.0 introduced breaking changes by implementing Socket.IO protocol v5. This makes it incompatible with older Socket.IO server/client versions.
fix
Ensure that `socket.io-msgpack-parser` v3.x is used exclusively with Socket.IO server/client versions 3.x or 4.x. If using older Socket.IO versions (1.x/2.x), you must use `socket.io-msgpack-parser` v2.x.
affects: >=3.0.0
gotchaThis parser MUST be used on both the Socket.IO server and client sides. Failing to do so will result in connection failures or unhandled protocol errors due to mismatched encoding/decoding strategies.
fix
Always pass `parser: customParser` to both the `socket.io` server instance and the `socket.io-client` client instance during initialization.
affects: >=1.0.0
gotchaUsing the MessagePack parser increases the browser bundle size compared to the default JSON parser. It adds approximately 7.5 KB (minified) or 3.0 KB (gzipped) to the client-side JavaScript bundle.
fix
Consider the trade-off between smaller message sizes (binary) and initial bundle size. This parser is generally recommended for applications prioritizing network efficiency over minimal initial client footprint.
affects: >=1.0.0
Errors
Common errors & fixes
protocol mismatch
Socket.IO server and client are using different versions of the protocol, often caused by mismatched `socket.io` and `socket.io-msgpack-parser` versions.
fix
Verify that `socket.io-msgpack-parser` v3.x is paired with Socket.IO v3.x/4.x, or v2.x with Socket.IO v1.x/2.x. Update or downgrade dependencies to ensure compatibility on both ends.
Error: Invalid packet format
The parser received data that does not conform to the expected MessagePack or Socket.IO packet structure, typically due to mismatched parsers or corrupted data.
fix
Confirm that both client and server are configured to use `socket.io-msgpack-parser`. Check for any intermediate proxies or network issues that might be corrupting data.
TypeError: customParser is not a constructor
Incorrect import statement in an ESM or TypeScript environment. The package provides a default export, not a named export that acts as a constructor.
fix
Use `import customParser from 'socket.io-msgpack-parser';` for ESM, or `const customParser = require('socket.io-msgpack-parser');` for CommonJS.
Upgrade
Version history
3.0.2latest on npm
Audit
Dependencies
socket.iorequiredRequired on the server-side to configure the Socket.IO instance to use this custom parser.
socket.io-clientrequiredRequired on the client-side to configure the Socket.IO client instance to use this custom parser.
Agent activity
6 hits · last 30 days
node
4
OpenAI (training)
1
Resources
socket.io-msgpack-parser — npm install socket.io-msgpack-parser · libregistry