N
Nuxt4d ago
Juicy

Production environmental variables

Hi, I use IIS for hosting and im trying to setup my environmental variable that i use in runtime config. How do i do that on prod? I remember using some file to do it before but I forgot...
2 Replies
kapa.ai
kapa.ai4d ago
Hi @Juicy. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- In production, Nuxt does not read your .env file. Instead, you must set environment variables using your hosting environment's tools or configuration. This is a deliberate design choice to ensure compatibility with serverless and edge environments, which may not have a filesystem for .env files. For IIS (or any production server), you should set environment variables at the OS or web server level. Common approaches include: - Setting environment variables in the system settings (e.g., Windows Environment Variables). - Using the command line to set variables before starting your server:
set NUXT_API_SECRET=your_secret_value
set NUXT_PUBLIC_API_BASE=<https://your-api-url>
node .output/server/index.mjs

set NUXT_API_SECRET=your_secret_value
set NUXT_PUBLIC_API_BASE=<https://your-api-url>
node .output/server/index.mjs

- Configuring them in your IIS application pool or web.config if supported. You cannot rely on a .env file in production—that file is only used during development, build, and generate time. After building your Nuxt app, you must set the variables explicitly in your production environment for them to be available at runtime. For more details, see the official documentation: Nuxt .env in production and Runtime Config. If you previously used a file, it was likely during development or build, not at runtime in production. In production, always use environment variables set by your server or OS, not a .env file. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4d ago
<@349656144144498701> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?