Complete the code to access an environment variable in Astro.
const apiKey = import.meta.env.[1];
In Astro, environment variables that start with PUBLIC_ are exposed to the client and accessed via import.meta.env.PUBLIC_API_KEY.
Complete the code to safely use an environment variable with a fallback value.
const apiUrl = import.meta.env.PUBLIC_API_URL || [1];
Using the logical OR operator || allows setting a fallback URL if the environment variable is not defined.
Fix the error in accessing a private environment variable in Astro.
const secret = import.meta.env.[1];
Only environment variables prefixed with PUBLIC_ are accessible in client-side Astro code. Private variables are not exposed.
Fill both blanks to create a server-side environment variable access with fallback.
const dbPassword = process.env.[1] || [2];
Server-side environment variables are accessed via process.env. Providing a fallback string ensures the code works if the variable is missing.
Fill all three blanks to destructure and use environment variables in Astro.
const { [1], [2] } = import.meta.env;
const apiKey = [3] || "defaultKey";Destructuring import.meta.env allows easy access to multiple public environment variables. Use the destructured variable for fallback logic.