start
start(
options):Promise<void>
Defined in: index.cts:244
Starts a WebSocket server bound to the given address and spawns worker threads that handle WebSocket events.
Parameters
Section titled “Parameters”options
Section titled “options”Configuration object:
- bind: Required. Address string to bind the server to (e.g. “127.0.0.1:8080”), or an array of such strings to bind multiple addresses.
- workerPath: Required. Path (absolute or relative to process.cwd()) to the
worker JavaScript module. This module will be imported in each
worker thread and its exported handlers will be registered with
the native addon. Worker modules may export any subset of the
WorkerInterfacehandlers. - threads: Optional. Number of worker threads to spawn. When a positive
integer is provided, that number of Node.js
Workerthreads are created and set up to handle WebSocket events. When omitted, defaults to the number of CPU cores or 4, whichever is higher. - workerArg: Optional. Argument to pass to the handleStart() method of worker modules, if they implement it. This allows passing initialization data or configuration to workers.
string | string[]
workerPath?
Section titled “workerPath?”string
threads?
Section titled “threads?”number
workerArg?
Section titled “workerArg?”any
Returns
Section titled “Returns”Promise<void>
A Promise that resolves after worker threads (if any) have been started and the native addon has been instructed to bind to the address. The Promise rejects if worker initialization fails.
Throws
Section titled “Throws”If options is or the bind and workerPath properties are
missing or invalid, or if already started.