---
sidebar_label: port
---

# server.port

- **Type:** `number`
- **Default:** `8080`

When Modern.js executes `dev`, `start` and `serve` commands, it will start with `8080` as the default port, and will automatically increment the port number when the port is occupied. You can change the port number of Server through this config:

```js title="modern.config.ts"
export default defineConfig({
  server: {
    port: 3000,
  },
});
```

### Difference with dev.port

In most cases, we recommend using `server.port` instead of `dev.port` to set the port number, the differences between them are as follows:

- `dev.port` only takes effect in the development, and `server.port` takes effect in both development and production.
- In the development, `dev.port` takes precedence over `server.port`.

When you set `dev.port` and `server.port` at the same time, `dev.port` will take effect in the development, and `server.port` will take effect in the production. For example, in the following example, the port in the development is `3001`, and the port in the production is `3002`.

```ts title="modern.config.ts"
export default defineConfig({
  dev: {
    port: 3001,
  },
  server: {
    port: 3002,
  },
});
```
