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.

npm install respjs
INSTALL
IMPORT
SIG · RESPJS
R
respjs
databasejavascriptv4.2.0
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.

Resp
const Resp = require('respjs')
import Resp from 'respjs'
The library is CommonJS-only; there is no default ESM export in version 4.2.0.
Resp.decode
const buf = Resp.decode(buffer, false)
Resp.decode(buffer, bufBulk: true)
Second argument is a boolean for bufBulk, not an object.
Resp.encodeRequest
Resp.encodeRequest(['set', 'key', value])
Resp.encodeRequest('set', 'key', value)
Takes a single array argument, not multiple arguments.

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 issues
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.
fix
Always pipe a stream or provide complete RESP chunks; use resp.write() only when you have full frames.
affects: >=0.0.0
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.
fix
Use encodeBulk for data strings, encodeString for simple reply strings like 'OK'.
affects: >=0.0.0
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.
fix
Pass { bufBulk: true } in the constructor to get Buffer objects for bulk data.
affects: >=0.0.0
gotchaencodeNullArray() is missing from the documentation; the example code uses encodeNull() for both null and null array. Actually, there is a separate encodeNullArray method.
fix
Use encodeNullArray() for RESP null arrays (*-1\r\n) instead of encodeNull().
affects: >=4.0.0
Errors
Common errors & fixes
TypeError: Resp.decode is not a function
Using import statement on a CommonJS module without correct interop.
fix
Use require('respjs') or use default import with esModuleInterop in TypeScript.
Error: Protocol error: unexpected character
Feeding incomplete or malformed RESP data to resp.write().
fix
Ensure you are writing complete RESP frames; consider using a stream and pipe instead.
TypeError: Resp.encodeRequest is not a function
Calling Resp.encodeRequest with multiple arguments (e.g., 'set','key') instead of an array.
fix
Wrap arguments in an array: Resp.encodeRequest(['set', 'key', value]).
Upgrade
Version history
4.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Meta
1
Resources
packagerespjs
respjs — npm install respjs · libregistry