🌿 Nuxt.js Intermediate

What is `useRuntimeConfig` in Nuxt.js?

Answer

useRuntimeConfig() is a composable that provides access to runtime configuration variables defined in nuxt.config.ts under the runtimeConfig key. It is the recommended way to access environment variables in Nuxt instead of using process.env directly. On the server, it returns both private and public config. On the client, only runtimeConfig.public values are accessible for security reasons. Nuxt automatically maps environment variables to runtime config: setting NUXT_PUBLIC_API_BASE in .env overrides runtimeConfig.public.apiBase at runtime without rebuilding, enabling dynamic configuration in containerized deployments.