> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# server.port

- **Type:** `number`
- **Default:** `3000`

Sets the port number for the Rsbuild server.

By default, the Rsbuild server listens on port `3000` and automatically increments the port when it's occupied. Enable [server.strictPort](/config/server/strict-port.md) to throw an error instead of incrementing the port when it's occupied.

The Rsbuild CLI provides a [--port](/guide/basic/cli.md#rsbuild) option to set the port number. The `--port` option takes priority over the `server.port` config.

```bash
npx rsbuild --port 8080
```

## Example

Set the port to `8080`:

```ts title="rsbuild.config.ts"
export default {
  server: {
    port: 8080,
  },
};
```

Set different port numbers for development and preview servers:

```ts title="rsbuild.config.ts"
export default {
  server: {
    port: process.env.NODE_ENV === 'development' ? 3000 : 8080,
  },
};
```

## Dynamic port

Set `server.port` to `0` to let the operating system assign an available port:

```ts title="rsbuild.config.ts"
export default {
  server: {
    port: 0,
  },
};
```

This is particularly useful in test scenarios, as it avoids port conflicts when multiple tests start Rsbuild servers simultaneously.

## Version history

| Version | Changes                                                     |
| ------- | ----------------------------------------------------------- |
| v2.2.0  | Added support for dynamic ports by setting the value to `0` |
