Registry / database / respjs

respjs

JSON →
library4.2.0jsnpmunverified

An implementation of the REdis Serialization Protocol (RESP) for Node.js. Version 4.2.0 is stable, with infrequent releases. It provides encoding and decoding of RESP data (simple strings, errors, integers, bulk strings, arrays, nulls) as buffers. Key differentiators: low-level protocol handling, stream-based parsing, and support for pipelining. Unlike higher-level Redis clients, respjs focuses solely on the wire protocol, making it suitable for building custom Redis clients or tools. It is a dependency of thunk-redis and other libraries.

database
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.

The library is CommonJS-only; there is no default ESM export in version 4.2.0.

const Resp = require('respjs')

Second argument is a boolean for bufBulk, not an object.

const buf = Resp.decode(buffer, false)

Takes a single array argument, not multiple arguments.

Resp.encodeRequest(['set', 'key', value])

Shows how to use respjs to parse RESP data from a TCP socket to a Redis server, sending a PING command.

const Resp = require('respjs'); const { Socket } = require('net'); const client = new Socket(); client.connect(6379, '127.0.0.1', () => { const resp = new Resp(); resp.on('data', (data) => { console.log('Received:', data); }); resp.on('error', (err) => { console.error('Parse error:', err); }); client.pipe(resp); // Send a simple Redis command: PING client.write(Resp.encodeRequest(['PING'])); }); client.on('close', () => { const resp = new Resp(); resp.end(); });
Debug
Known footguns
gotchaThe Resp class is an EventEmitter that expects to be piped from a Readable stream (e.g., socket). If you call resp.write() manually, you must ensure chunks are complete; otherwise, partial data causes parse errors.
gotchaencodeBulk and encodeString produce different RESP types. encodeBulk is for bulk strings (with length prefix), encodeString is for simple strings (no length prefix). Mixing them can cause protocol errors.
gotchaThe bufBulk option (default false) controls whether bulk strings are returned as Buffers or decoded as UTF-8 strings. If you expect binary data, set bufBulk to true.
gotchaencodeNullArray() is missing from the documentation; the example code uses encodeNull() for both null and null array. Actually, there is a separate encodeNullArray method.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources
packagerespjs