> ## Documentation Index
> Fetch the complete documentation index at: https://nextjs-egg.nyxel.my.id/llms.txt
> Use this file to discover all available pages before exploring further.

# Run Modes

> Switch between production and development mode for your Next.js app.

Set the `NODE_RUN_ENV` variable in the panel to control how the egg builds and starts your Next.js app. The two supported values are `production` and `development`.

<Tabs>
  <Tab title="Production">
    Set `NODE_RUN_ENV` to `production`.

    In production mode, the egg runs `next build` before starting the server. This compiles your app into an optimized output — smaller bundles, static generation, and better runtime performance.

    **Startup sequence:**

    1. Install dependencies
    2. Run `next build` (this can take a minute or more depending on your app's size)
    3. Run `next start -p $SERVER_PORT`

    **Requirements:**

    * All environment variables needed at build time must be present before the server starts. Use the [`.env.pterodactyl` injection method](/guides/env-injection) to supply them.
    * Missing build-time env vars will cause `next build` to fail.

    **Best for:** live sites, staging environments, and any deployment where performance matters.
  </Tab>

  <Tab title="Development">
    Set `NODE_RUN_ENV` to `development`.

    In development mode, the egg skips the build step entirely and runs `next dev` directly. The dev server compiles pages on demand and supports hot-reload — changes to your source files reflect in the browser without restarting the server.

    **Startup sequence:**

    1. Install dependencies
    2. Run `next dev -p $SERVER_PORT` (no build step)

    **Trade-offs:**

    * Slower page loads and higher CPU usage than production mode
    * Not optimized for serving real users

    **Best for:** active development, testing changes, and debugging.
  </Tab>
</Tabs>

## Port configuration

Your app must not hardcode a port. The egg passes `SERVER_PORT` to Next.js at runtime via the `-p` flag. Do not set a fixed port in `next.config.js` — it will conflict with the value the egg provides.

## Startup detection

The panel marks your server as **Started** when it sees one of these strings in the console output:

| String                  | Emitted by                      |
| ----------------------- | ------------------------------- |
| `ready on`              | Next.js 13 and earlier          |
| `started server on`     | Next.js internals               |
| `Local:        http://` | Next.js 14+ dev output          |
| `Compiled successfully` | Dev mode compilation            |
| `listening on`          | Custom server or adapter output |
| `▲ Next.js`             | Next.js 13+ startup banner      |

If your server stays at **Starting...** indefinitely, confirm that your app is writing one of these strings to stdout. Custom startup wrappers or logging libraries that suppress stdout may prevent detection.
