Skip to content
// EFFECT DAYS 2026

NodeSocket unstable

Node.js socket constructors and layers for Effect sockets.

This module re-exports the shared Node socket support for TCP connections, Unix domain socket connections, and Node Duplex streams. It also provides WebSocket client layers backed by Node's global WebSocket.

2 exports Since v4.0.0 Source

Layers

Since v4.0.0

Creates a Socket.Socket layer for a WebSocket URL using the Node WebSocket constructor layer, honoring protocol, handshake-header, open-timeout, and high-water-mark options.

Signature

declare const layerWebSocket: (url: string | Effect.Effect<string>, options?: {
readonly headers?: Readonly<Record<string, string>>;
readonly highWaterMark?: number;
readonly openTimeout?: Duration.Input;
readonly protocols?: string | Array<string>;
}) => Layer.Layer<Socket.Socket, never, never>

Provides a Socket.WebSocketConstructor backed by Node's global WebSocket.

Details

Handshake headers and subprotocols in client options objects are passed to the constructor as Node's WebSocketInit.

Gotchas

Use NodeWS.layerWebSocketConstructor if any of these matter:

  • Reads cannot be paused, so incoming frames are buffered without limit, or fail the socket with a SocketReadError once a configured highWaterMark is exceeded.
  • A custom Host header is ignored.
  • Outgoing messages are not compressed.

Signature

declare const layerWebSocketConstructor: Layer.Layer<Socket.WebSocketConstructor>