bare-sidecar
Start and manage Bare sidecar processes from Node.js and Electron
stable
bare-sidecar — Start and manage Bare sidecar processes from Node.js and Electron.
npm i bare-sidecarUsage
In the host process:
const Sidecar = require('bare-sidecar')
const sidecar = new Sidecar(require.resolve('./entry'))
sidecar
.on('exit', (code, status) => {
// The sidecar process exited
})
.on('data', (data) => {
// Received data from the sidecar over IPC
})
.write('Hello sidecar')In the sidecar entry (entry.js), the IPC channel is available as a stream on Bare.IPC:
Bare.IPC.on('data', (data) => Bare.IPC.write(data))API
Sidecar
new Sidecar(entry: string, args?: string[], opts?: SidecarOptions)
Spawn a bundled Bare runtime running entry and return a Sidecar. entry is the path to the module to run, typically resolved with require.resolve(). args is an array of additional command line arguments passed to the process. options is reserved for future use.
Overloads:
new Sidecar(entry: string, args?: string[], opts?: SidecarOptions)
new Sidecar(entry: string, opts?: SidecarOptions)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
entry | string | — | Path to the module the sidecar process runs, typically resolved with require.resolve(). |
args? | string[] | — | Additional command-line arguments passed to the process (default []). |
opts? | SidecarOptions | — | Reserved for future use. |
stderr: Pipe | null
The readable standard error stream of the underlying process.
stdin: Pipe | null
The writable standard input stream of the underlying process.
stdout: Pipe | null
The readable standard output stream of the underlying process.
Types
SidecarEvents
interface SidecarEvents {
exit: [code: number | null, signalCode: string | null]
data: [data: unknown]
end: []
readable: []
piping: [dest: Writable]
close: []
error: [err: Error]
drain: []
finish: []
pipe: [src: Readable]
}SidecarOptions
interface SidecarOptions {
}See also
- Builds on
bare-fs,bare-module,bare-path,bare-pipe,bare-stream,bare-subprocess, andbare-url. - The instance extends a duplex stream: writing to it sends data to the sidecar over its IPC channel, data received from the sidecar is emitted as
'data'events, and destroying the stream kills the sidecar process. - The
'close'event is emitted after the sidecar process has exited and its underlying stream has been destroyed. bare-subprocess— the lower-level process API.- One core, many platforms — running a Bare core beside a host.
- Bare modules — the full
bare-*catalog. - Bare runtime API — the runtime these modules extend.