> ## 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.

# Env Injection

> Inject environment variables into your Next.js app using the panel File Manager.

Panel startup variables are visible to anyone with access to your server's configuration. For secrets like API keys, database URLs, or third-party credentials, use env injection instead: upload a `.env.pterodactyl` file through the File Manager and the egg copies it to `.env` before the app starts.

<Note>
  The copy happens before `npm install` and `next build`, so environment variables are available at both install time and build time.
</Note>

## How it works

At startup, the egg checks for a file named `.env.pterodactyl` in `/home/container/`. If it exists, the egg copies it to `/home/container/.env` before installing dependencies or running the build. Your Next.js app reads the resulting `.env` file as normal.

<Warning>
  Do not name the file `.env` directly. The egg looks specifically for `.env.pterodactyl`. Uploading a file named `.env` will not trigger the copy step.
</Warning>

## Steps

<Steps>
  <Step title="Create your .env file locally">
    Create a `.env` file on your machine with all the environment variables your app requires:

    ```bash .env theme={null}
    DATABASE_URL=postgres://user:pass@host:5432/db
    NEXTAUTH_SECRET=your-secret-here
    NEXT_PUBLIC_API_URL=https://api.example.com
    ```
  </Step>

  <Step title="Rename the file">
    Rename the file from `.env` to `.env.pterodactyl`. The name must match exactly.
  </Step>

  <Step title="Open the File Manager">
    In the panel, open the **File Manager** for your server and navigate to `/home/container/`.
  </Step>

  <Step title="Upload the file">
    Upload `.env.pterodactyl` to `/home/container/`. If a file with that name already exists, replace it.
  </Step>

  <Step title="Restart the server">
    Restart the server. The egg copies `.env.pterodactyl` to `.env` automatically before running `npm install` and `next build`.
  </Step>
</Steps>

<Tip>
  If you update your environment variables, re-upload `.env.pterodactyl` and restart the server. The egg overwrites `.env` on every startup.
</Tip>
