Bun.spawn() to spawn a child process. When spawning a second bun process, you can open a direct inter-process communication (IPC) channel between the two processes.
This API is only compatible with other
bun processes. Use process.execPath to get a path to
the currently running bun executable.The parent process can send messages to the subprocess using the
.send() method on the returned Subprocess instance. A reference to the sending subprocess is also available as the second argument in the ipc handler.
Meanwhile the child process can send messages to its parent using with
process.send() and receive messages with process.on("message"). This is the same API used for child_process.fork() in Node.js.
All messages are serialized using the JSC
serialize API, which allows for the same set of transferrable types supported by postMessage and structuredClone, including strings, typed arrays, streams, and objects.
See Docs > API > Child processes for complete documentation.