#How to set environment variables at runtime (node ssr)
4 messages · Page 1 of 1 (latest)
Hi @latent badger. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Yes, Astro provides a way to handle runtime environment variables. If an .env file containing environment variables is present when the build process is run, these values will be hard-coded in the output. However, during the build, the runtime variables must be absent from the .env file, and you must provide Astro with every environment variable to expect at run-time. This signals to Astro that the actual value will be available when the built application is run. The placeholder value will be ignored by the build process, and Astro will use the value provided at run-time.
In the case of multiple run-time variables, store them in a separate file (e.g. .env.runtime) from .env. Start the build with the following command:
export $(cat .env.runtime) && astro build
This command will load the environment variables from the .env.runtime file and then run the astro build command. The environment variables will be available at runtime when the built application is run.
For more information, you can refer to the Astro documentation on Runtime Environment Variables (https://docs.astro.build/en/guides/integrations-guide/node#runtime-environment-variables).
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@latent badger kapa.ai is still learning and improving, please let us how it did by reacting below