Skip to content

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.

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 WorkerInterface handlers.
  • threads: Optional. Number of worker threads to spawn. When a positive integer is provided, that number of Node.js Worker threads 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[]

string

number

any

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.

If options is or the bind and workerPath properties are missing or invalid, or if already started.