> ## Documentation Index
> Fetch the complete documentation index at: https://anvil.thatdevguy.in/llms.txt
> Use this file to discover all available pages before exploring further.

# anvil start: Run Your Built Production Server Bundle

> Launch the production server bundle built by anvil build, with an optional port override via flag or the PORT environment variable.

Run `anvil start` to execute the production bundle generated by `anvil build`. The command spawns the bundle as a child Node.js process, inheriting stdio so logs appear in your terminal or platform's log drain. This is the command you call in `Dockerfile` `CMD` entries, process manager configs, and deploy scripts.

## Usage

```bash theme={null}
anvil start [options]
```

## Flags

<ParamField query="-e, --entry <file>" type="string" default="dist/server.mjs">
  Path to the bundle produced by `anvil build`. If the file does not exist, `anvil start` prints an error and exits with code `1` — it will not attempt to build it automatically.
</ParamField>

<ParamField query="-p, --port <port>" type="number">
  Override the HTTP port. When provided, this value is forwarded to the child process as the `PORT` environment variable, taking precedence over any `PORT` already set in the environment. When omitted, the bundle falls back to `PORT` from the environment, then to `3000`.
</ParamField>

## Port resolution order

The port used by the running server follows this precedence, from highest to lowest:

1. `--port <port>` flag passed to `anvil start`
2. `PORT` environment variable already set in the shell
3. Default value of `3000` hardcoded in the generated bundle entry point

## Example: basic deploy script

A typical deploy pipeline builds the project then starts it:

```bash theme={null}
# Build the production artifact
anvil build

# Start the server
anvil start
```

## Example: custom port

```bash theme={null}
anvil start --port 8080
```

## Example: custom bundle path

```bash theme={null}
anvil start --entry build/app.mjs --port 8080
```

## Example: using PORT from the environment

```bash theme={null}
PORT=443 anvil start
```

## Example: Docker

```dockerfile theme={null}
FROM node:20-slim
WORKDIR /app

COPY package*.json ./
RUN npm ci --omit=dev

COPY . .
RUN npx anvil build

EXPOSE 3000
CMD ["npx", "anvil", "start"]
```

## Error: bundle not found

If you run `anvil start` before `anvil build`, you will see:

```text theme={null}
[anvil] /absolute/path/to/dist/server.mjs not found — run `anvil build` first
```

<Warning>
  `anvil start` does **not** watch for file changes or restart on crashes. In production, wrap it with a process supervisor such as PM2, Docker restart policies, or your platform's native process management to get automatic restarts.
</Warning>

<Tip>
  For zero-downtime deploys, build the new bundle alongside the running server, then send a signal to swap. Because `anvil start` spawns a standard Node.js child process, all normal graceful-shutdown patterns (`SIGTERM` handlers, drain logic) apply.
</Tip>
