Join the Nuxt Team at Frontend Nation 4-7 June.

Runtime Config

Learn how to migrate from Nuxt 2 to Nuxt 3 runtime config.

If you wish to reference environment variables within your Nuxt 3 app, you will need to use runtime config.

When referencing these variables within your components, you will have to use the useRuntimeConfig composable in your setup method (or Nuxt plugin).

In the server/ portion of your app, you can use useRuntimeConfig without any import.

Read more in Docs > Guide > Going Further > Runtime Config.

Migration

  1. Add any environment variables that you use in your app to the runtimeConfig property of the nuxt.config file.
  2. Migrate process.env to useRuntimeConfig throughout the Vue part of your app.
export default defineNuxtConfig({
  runtimeConfig: {
    // Private config that is only available on the server
    apiSecret: '123',
    // Config within public will be also exposed to the client
    public: {
      apiBase: '/api'
    }
  },
})