#How do I know if I'm in DEV in convex?

3 messages · Page 1 of 1 (latest)

latent stump
#

How do I know if I'm in DEV in convex?

celest doveBOT
#

Hi @latent stump. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

There's no built-in environment variable in Convex that reliably indicates whether you're in a dev vs. production deployment. Notably, NODE_ENV is not a reliable indicator — it is currently set to "production" everywhere in Convex (both dev and prod deployments). [NODE_ENV thread]

Recommended approach: Create your own environment variable

The recommended strategy is to define your own custom environment variable (e.g., CONVEX_ENV) and set it differently per deployment via the Convex dashboard. [NODE_ENV thread]

Steps:

  1. Go to your development deployment settings on the Convex dashboard and add:

    • Name: CONVEX_ENV
    • Value: development
  2. Go to your production deployment settings and add:

    • Name: CONVEX_ENV
    • Value: production
  3. Access it in your Convex functions using process.env:

const isDev = process.env.CONVEX_ENV === "development";

You can also set environment variables from the CLI: [Environment Variables]

npx convex env set CONVEX_ENV 'development'

Since environment variables are set per deployment, the same variable name will return different values depending on which deployment is running. [Environment Variables]

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: