Child process

subprocess.send()

Queues a message over IPC. Delivery acceptance is not evidence that the remote action succeeded; use an application reply and correlation ID. Tested on Node.js 22.16.0. Example output (one line per entry): ["true"].

Formal Syntax & Structure

nodejs syntaxnodejs
subprocess.send(message[, sendHandle[, options]][, callback])

Parameters & Attributes

NameTypeDescription
messageunknownSerializable message.
sendHandleobjectOptional supported handle.
optionsobjectSend settings.
callbackFunctionCompletion callback.

Return Value

boolean

IPC flow-control indication.

Working Example

Example Snippetnodejs
import { writeFileSync, unlinkSync } from 'node:fs';import { fork } from 'node:child_process';import { once } from 'node:events';const file = new URL('./child.cjs', import.meta.url);writeFileSync(file, "process.on('message',m=>{process.send({id:m.id+1},()=>process.disconnect());});");let c;try {    c = fork(file, [], { env: {}, stdio: ['ignore', 'ignore', 'ignore', 'ipc'] });    const done = once(c, 'close');    const reply = once(c, 'message');    c.send({ id: 3 });    const result = (await reply)[0];    console.log(result.id === 4);    await done;}finally {    if (c?.exitCode === null && c.signalCode === null)        c.kill();    unlinkSync(file);}
Node.js Reference