---
title: "Environments and deployments"
description: "The deployments an app has, from your dev one to production, what BACKEND_ENVIRONMENT decides for each, the env the Nuxt app reads versus the env the deployment holds, and the platform's own variables."
canonical_url: "https://nuxt-backend.dev/docs/start/concepts/environments"
---
# Environments and deployments

> The deployments an app has, from your dev one to production, what BACKEND_ENVIRONMENT decides for each, the env the Nuxt app reads versus the env the deployment holds, and the platform's own variables.

Version: nuxt-backend 0.6.x · Tab: Start · Kind: concept · Status: stable

Every page: [llms.txt](https://nuxt-backend.dev/llms.txt) · Skill for coding agents: [nuxt-backend](https://nuxt-backend.dev/.well-known/skills/nuxt-backend/SKILL.md)

Commands use npm; use your project's package manager.

An app has one deployment per stage: a dev deployment for each developer, a preview per branch, and one production. One variable, `BACKEND_ENVIRONMENT`, tells the backend which kind it runs on, and every mode follows from it: email test mode, Polar's sandbox, trusted local origins and sign-in codes in the logs. You never flip those one by one.

## The deployments

<table>
<thead>
  <tr>
    <th>
      Deployment
    </th>
    
    <th>
      <code>
        CONVEX_DEPLOYMENT
      </code>
    </th>
    
    <th>
      Made by
    </th>
    
    <th>
      <code>
        BACKEND_ENVIRONMENT
      </code>
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      Account-free local
    </td>
    
    <td>
      <code>
        anonymous:…
      </code>
    </td>
    
    <td>
      <code>
        npx nuxt-backend dev --anonymous
      </code>
      
      , on any OS, with no account
    </td>
    
    <td>
      <code>
        development
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Local
    </td>
    
    <td>
      <code>
        local:…
      </code>
    </td>
    
    <td>
      <code>
        convex dev
      </code>
      
       in an account's project, on this machine
    </td>
    
    <td>
      <code>
        development
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Cloud dev
    </td>
    
    <td>
      <code>
        dev:…
      </code>
    </td>
    
    <td>
      <code>
        convex dev
      </code>
      
       in an account's project, one per developer
    </td>
    
    <td>
      <code>
        development
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Preview
    </td>
    
    <td>
      Named by the branch
    </td>
    
    <td>
      <code>
        convex deploy
      </code>
      
       with a preview deploy key
    </td>
    
    <td>
      <code>
        preview
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Demo or staging
    </td>
    
    <td>
      <code>
        prod:…
      </code>
      
      , in a project of its own
    </td>
    
    <td>
      <code>
        convex deploy
      </code>
      
       with that project's production key, as the <a href="https://nuxt-backend.dev/docs/start/tutorial">
        Panels demo
      </a>
      
       runs
    </td>
    
    <td>
      <code>
        sandbox
      </code>
      
      , set on purpose
    </td>
  </tr>
  
  <tr>
    <td>
      Production
    </td>
    
    <td>
      <code>
        prod:…
      </code>
    </td>
    
    <td>
      <code>
        convex deploy
      </code>
      
       with a production deploy key
    </td>
    
    <td>
      <code>
        production
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Self-hosted
    </td>
    
    <td>
      None: <code>
        CONVEX_SELF_HOSTED_URL
      </code>
      
       names it
    </td>
    
    <td>
      Your own Convex backend
    </td>
    
    <td>
      What you set
    </td>
  </tr>
</tbody>
</table>

## `BACKEND_ENVIRONMENT`

`BACKEND_ENVIRONMENT` takes `development`, `preview`, `sandbox` or `production`. `npx nuxt-backend env push` derives it from `CONVEX_DEPLOYMENT`: a dev deployment is `development`, a preview is `preview`, and production is `production`. Each value decides four things at once:

<table>
<thead>
  <tr>
    <th>
      <code>
        BACKEND_ENVIRONMENT
      </code>
    </th>
    
    <th>
      Email
    </th>
    
    <th>
      Billing
    </th>
    
    <th>
      Local origins trusted
    </th>
    
    <th>
      Sign-in codes logged
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        development
      </code>
    </td>
    
    <td>
      Test mode
    </td>
    
    <td>
      Polar's sandbox
    </td>
    
    <td>
      Yes
    </td>
    
    <td>
      Yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        preview
      </code>
    </td>
    
    <td>
      Test mode
    </td>
    
    <td>
      Polar's sandbox
    </td>
    
    <td>
      No
    </td>
    
    <td>
      No
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        sandbox
      </code>
    </td>
    
    <td>
      Test mode
    </td>
    
    <td>
      Polar's sandbox
    </td>
    
    <td>
      No
    </td>
    
    <td>
      No
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        production
      </code>
    </td>
    
    <td>
      Live
    </td>
    
    <td>
      Live
    </td>
    
    <td>
      No
    </td>
    
    <td>
      No
    </td>
  </tr>
</tbody>
</table>

`sandbox` is the one value you set by hand. It is for a deployed demo or a staging app: the deployment runs in production mode, with production's checks and no code logging, while every provider stays in its test mode. The monitoring environment name equals `BACKEND_ENVIRONMENT` too, so Sentry groups a demo's errors apart from production's. A `sandbox` deployment also refuses the admin actions that reach a provider for real: a broadcast, a webhook replay and lifting an email suppression ([What a demo refuses](https://nuxt-backend.dev/docs/ship/deploy/staging#what-a-demo-refuses)). The replay and the lift run on `production` and `development` alone, so a preview, or a deployment whose value is unset or mistyped, refuses them too.

`BACKEND_ENVIRONMENT` replaces five variables of earlier previews, each of which said one part of the same thing: `EMAIL_TEST_MODE`, `BILLING_ENVIRONMENT`, `MONITORING_ENVIRONMENT`, `AUTH_TRUST_LOCAL_ORIGINS` and `NUXT_BACKEND_LOG_OTP`.

## Sandbox and production providers

Every provider starts in its test mode, and only `production` takes it out:

- **Email** in test mode delivers only to Resend's test addresses, such as `delivered@resend.dev`. Any other address is refused on the request, with a message that says why.
- **Billing** outside production calls Polar's sandbox, with a sandbox token, a sandbox catalog and the test card `4242 4242 4242 4242`.
- **AI** calls the same models everywhere, through the Convex AI Gateway or `AI_GATEWAY_API_KEY`, and charges credits from whichever billing the environment uses.

`npx nuxt-backend doctor --prod` fails a production deployment whose `BACKEND_ENVIRONMENT` is unset, `development` or `preview`. It only warns on `sandbox`, which you set on purpose for a demo or staging app ([Prepare for launch](https://nuxt-backend.dev/docs/ship/checklist)). [Develop on real sandboxes](https://nuxt-backend.dev/docs/develop/sandboxes) covers each test mode in development.

## The app's env and the deployment's

Most values live on the deployment, and the package forwards them there for you:

<table>
<thead>
  <tr>
    <th>
      Where
    </th>
    
    <th>
      What lives there
    </th>
    
    <th>
      Who puts it there
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      The deployment
    </td>
    
    <td>
      <code>
        AUTH_SECRET
      </code>
      
      , <code>
        SITE_URL
      </code>
      
      , <code>
        BACKEND_ENVIRONMENT
      </code>
      
      , and the email, billing, AI, push and monitoring keys
    </td>
    
    <td>
      <code>
        npx nuxt-backend env push
      </code>
      
       from <code>
        .env.local
      </code>
      
      , or the dashboard
    </td>
  </tr>
  
  <tr>
    <td>
      The Nuxt app
    </td>
    
    <td>
      The backend's URL, <code>
        NUXT_PUBLIC_BACKEND_URL
      </code>
      
      , and the bot challenge's public site key
    </td>
    
    <td>
      The URL derives from <code>
        CONVEX_DEPLOYMENT
      </code>
      
       in development, and the deploy sets it on a host. The site key is yours to set
    </td>
  </tr>
  
  <tr>
    <td>
      Both
    </td>
    
    <td>
      The few values the app's server and the backend must agree on, such as the bot-check proof secret
    </td>
    
    <td>
      <code>
        env push
      </code>
      
      , and your host's env
    </td>
  </tr>
</tbody>
</table>

Write every value once in `.env.local`. The Nuxt app reads its part, and `env push` forwards the deployment's part, never replacing a value already set unless you pass `--force`. The app needs no second URL for the deployment's HTTP routes: it derives that origin from `NUXT_PUBLIC_BACKEND_URL`. [Environment variables](https://nuxt-backend.dev/docs/reference/configuration/environment-variables#every-variable) says where each name lives, grouped as Backend, Email, Billing, AI, Protection, Notifications and Monitoring, with the platform's names last.

## Regions

Where each deployment runs is chosen when it is created, and each service decides it in its own way:

- **Convex** picks the deployment's region at creation: the US, the EU in Dublin, Canada or Australia. Moving a deployment means a backup and a restore ([Convex](https://nuxt-backend.dev/docs/services/convex)).
- **Resend** sends from the region `EMAIL_REGION` names, while the account's data stays in the US ([Resend](https://nuxt-backend.dev/docs/services/resend)).
- **The AI gateway** can pin inference to the EU ([AI gateway](https://nuxt-backend.dev/docs/services/ai-gateway)).

Pick the same region for every deployment of an app, so a preview behaves like production. [Privacy, GDPR and cookies](https://nuxt-backend.dev/docs/ship/compliance/privacy) says what each region means for the data you hold.

## The platform's own variables

`CONVEX_DEPLOYMENT`, `CONVEX_DEPLOY_KEY`, `CONVEX_SITE_URL` and `CONVEX_SELF_HOSTED_URL` belong to the Convex CLI and runtime. The package reads them to find the deployment and derive its URLs, and never asks you to write or rename one: `convex dev` writes `CONVEX_DEPLOYMENT`, your host holds the deploy key, and the runtime sets `CONVEX_SITE_URL` itself.

## What this means for you

- In development: write values into `.env.local` and run `npx nuxt-backend env push` ([Run the dev loop](https://nuxt-backend.dev/docs/develop/dev-loop)).
- Connecting a service: its [Services](https://nuxt-backend.dev/docs/services) page lists its keys for dev and production.
- For previews and production: [Preview environments](https://nuxt-backend.dev/docs/ship/deploy/previews) and [Deploy to production](https://nuxt-backend.dev/docs/ship/deploy#the-env-split) set the env per stage, and [Self-host and add domains](https://nuxt-backend.dev/docs/ship/deploy/self-hosting#self-host-the-backend) covers your own backend.
- Before launch: pass `npx nuxt-backend doctor --prod` ([Diagnose your setup](https://nuxt-backend.dev/docs/develop/doctor)).


## Sitemap

See the full [sitemap](https://nuxt-backend.dev/sitemap.md) for all pages.
