Two required methods
Parser contract
Use a built-in parser for the official profiles, opt into the ecosystem compatibility parser, or provide one direct custom class or object. Parser selection and method binding happen once.
node-ipc/parsers and node-ipc/parsers/message share the package's Node defaults and Buffer-based transport contract. They do not run in web browsers, whether bundled or unbundled.
Official exports
import {
RawParser,
FastParser,
GuardedParser,
AssuredParser,
IPCProtocolError
} from 'node-ipc';
import {
createParser,
reservedEventTypes
} from 'node-ipc/parsers';| Export | Contract |
|---|---|
RawParser | Buffer pass-through and no node-ipc framing. |
FastParser / Parser | Direct JSON event envelopes separated by the configured delimiter. |
GuardedParser | Fast plus bounded frames and stream writes, envelope and name controls, and incomplete-frame timing. |
AssuredParser | Guarded plus a required event allow-list; the client/server runtime adds mutual-TLS or secure-local-server-root startup gates. |
IPCProtocolError | A receive-path protocol failure published as error. Streams close; UDP peer frame state resets. |
createParser(config) | Resolves the configured built-in, class, or object and checks the two required methods once. |
Custom class or object
class ApplicationParser {
constructor(config) {
this.delimiter = config.delimiter;
}
encode(type, data) {
// Return a string, Buffer, or Uint8Array accepted by the socket.
return encodeApplicationFrame(type, data);
}
read(remainder, chunk, receive) {
// Call receive({type, data}) once for every complete message.
// Return only the unconsumed remainder for the next chunk.
return decodeApplicationFrames(remainder, chunk, receive);
}
}
ipc.config.parser = ApplicationParser;
// An already-created ApplicationParser object is also accepted.| Member | Required | Meaning |
|---|---|---|
encode(type, data) | Yes | Produces the outbound wire value without node-ipc wrapping it again. |
read(remainder, chunk, receive) | Yes | Consumes complete frames, emits {type, data} objects in order, and returns the remaining partial frame. |
raw | No | When true, incoming Buffers go straight to data and read() is not on the receive path. |
maxPendingBytes | No | A positive finite byte limit selects the bounded stream-write handler once. |
messageTimeout | No | A truthy millisecond value selects incomplete-frame timing once. |
node-ipc does not layer Guarded validation around a custom parser. Validate framing, envelope shape, event names, sizes, and state directly if the trust boundary requires them. Throw IPCProtocolError for a receive-path violation that should publish error; stream failures close, while UDP peer frame state resets.
A parser class is constructed for each client/server. A parser object is used as supplied and may be shared if the same config object creates several endpoints; provide separate objects or keep it stateless.
js-message compatibility
import MessageParser from 'node-ipc/parsers/message';
ipc.config.parser = MessageParser;This official subpath preserves an ecosystem integration without putting js-message on the default path. It is explicit opt-in compatibility behavior: malformed envelopes become a message whose type is error. It is not a hardened decoder and does not add Guarded or Assured controls.
Use it when that behavior is part of the application contract. Use Guarded or Assured when you need node-ipc protocol containment, or extend an official parser when you need both compatibility and a reviewed policy.
Wire and transport notes
- Fast, Guarded, and Assured use UTF-8
{type, data}JSON envelopes followed byipc.config.delimiter. - Raw emits transport chunks. A TCP or local-socket chunk is not an application message boundary; the caller must frame its own protocol.
- Raw preserves each UDP datagram as one chunk. Framed profiles apply their own framing across datagrams and reset that peer's partial frame after a protocol error.
- UDP delivery, ordering, duplication, replay, identity, and confidentiality remain application concerns.
- Both peers must use compatible framing, event names, and Assured allow-lists. Custom parsers that own another encoding should return Buffers.
- Parser selection is per client/server instance. Built-in parsers and custom parser classes have per-endpoint instances.