#Checking if in dev or prod env

3 messages · Page 1 of 1 (latest)

naive kite
#

How can I check whether I am in development or in production?

old gorgeBOT
#

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

#

To check whether you are in development or production environment in Astro, you can use the default environment variables provided by Astro. Here's how you can do it:

const isProd = import.meta.env.PROD;
const isDev = import.meta.env.DEV;

These environment variables are boolean values:

  • import.meta.env.PROD: true if your site is running in production; false otherwise.
  • import.meta.env.DEV: true if your site is running in development; false otherwise. This is always the opposite of import.meta.env.PROD.

You can use these variables in your Astro components or scripts to conditionally execute code based on the environment.

Using environment variables provides more information on these and other default environment variables available in Astro.

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