# WebSocketServerOptions

**Kind:** Interface

**Source:** [`packages/websockets/interfaces/web-socket-server.interface.ts`](https://github.com/nestjs/nest/blob/master/packages/websockets/interfaces/web-socket-server.interface.ts#L4)

**Part of:** [Websockets](subsystem-packages-websockets)

`WebSocketServerOptions` defines the configuration required to initialize a WebSocket server. It specifies the network port the server listens on and the namespace used to scope or route WebSocket connections within the application.

## Properties

| Property | Type |
|---|---|
| `port` | `number` |
| `namespace` | `string` |

## Diagram

```mermaid
graph LR
  A[Application Configuration] --> B[WebSocketServerOptions]
  B --> C[port: number]
  B --> D[namespace: string]
  C --> E[WebSocket Server Listener]
  D --> F[Connection Namespace / Route]
```

## Usage

```ts
import type { WebSocketServerOptions } from './interfaces/web-socket-server.interface';

const websocketOptions: WebSocketServerOptions = {
  port: 3001,
  namespace: '/notifications',
};

// Pass the options when creating or configuring the WebSocket server.
createWebSocketServer(websocketOptions);
```

## AI Coding Instructions

- Provide a valid, available TCP port as `port`; avoid conflicting with the application's HTTP server port unless shared-server support exists.
- Use a consistent `namespace` format, typically beginning with `/`, such as `/chat` or `/notifications`.
- Keep namespace values aligned with the client connection URL and any server-side routing or gateway configuration.
- Treat this interface as configuration-only; do not add runtime connection state or server instances to it.

## How it works

`WebSocketServerOptions` is an exported TypeScript interface marked `@publicApi`. It describes an object with two required properties: [packages/websockets/interfaces/web-socket-server.interface.ts:1-7]

- `port: number` — a numeric `port` property. [packages/websockets/interfaces/web-socket-server.interface.ts:4-6]
- `namespace: string` — a string `namespace` property. [packages/websockets/interfaces/web-socket-server.interface.ts:4-7]

The interface itself contains no runtime validation, error handling, or side effects. [packages/websockets/interfaces/web-socket-server.interface.ts:4-7]
