Add Survey API URL to Environment Variable
Learn how to set up environment variables in Nuxt using the “runtimeConfig” API.
We'll cover the following
Environment variables
In order to ensure the application uses the service unique to each environment, we need to ensure the survey API URL is passed to the application through environment variables. This allows for hot switching of the values without having to change the application code.
Environment variables can be set up by placing the variable and the corresponding values in the .env
file at the base of the application. To make this variable available to the rest of the application, Nuxt provides a runtimeConfig
API that can be set from the Nuxt config file, and the variables can be accessed using the useRuntimeConfig
method.
Get hands-on with 1400+ tech skills courses.