Bird
0
0

You want to expose a public environment variable PUBLIC_API_URL to client-side code in Remix. How should you configure and access it?

hard📝 Application Q8 of 15
Remix - Deployment
You want to expose a public environment variable PUBLIC_API_URL to client-side code in Remix. How should you configure and access it?
AAdd it to .env and access via process.env.PUBLIC_API_URL in client code
BStore it in .env and import dotenv in client code
CPrefix the variable with REMIX_PUBLIC_ and access via import.meta.env.REMIX_PUBLIC_API_URL
DUse window.PUBLIC_API_URL set manually in HTML
Step-by-Step Solution
Solution:
  1. Step 1: Understand Remix public env variable convention

    Remix requires public env variables to be prefixed with REMIX_PUBLIC_ to expose them to client.
  2. Step 2: Access public env variables in client code

    Client code accesses these via import.meta.env.REMIX_PUBLIC_API_URL.
  3. Final Answer:

    Prefix the variable with REMIX_PUBLIC_ and access via import.meta.env.REMIX_PUBLIC_API_URL -> Option C
  4. Quick Check:

    Public env prefix and access = B [OK]
Quick Trick: Use REMIX_PUBLIC_ prefix for client env variables [OK]
Common Mistakes:
MISTAKES
  • Trying to access process.env on client
  • Not prefixing public env variables
  • Importing dotenv in client code

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Remix Quizzes