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
| Name | Type | Description |
|---|---|---|
| message | unknown | Serializable message. |
| sendHandle | object | Optional supported handle. |
| options | object | Send settings. |
| callback | Function | Completion 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);}