Nuxt

How can environment variables be managed during development and production in Nuxt?

December 4, 2025

download ready
Thank You
Your submission has been received.
We will be in touch and contact you soon!

Environment variables in Nuxt are managed through .env files and runtime configuration in nuxt.config.

Use .env files for separating dev and production settings, and expose necessary variables as public or private in runtime config. This approach ensures secure and environment-specific variable management.

Code

//.env.production
NUXT_API_URL=https://live.myapp.com/api

// nuxt.config.ts
export default defineNuxtConfig({
  runtimeConfig: {
    apiSecret: process.env.API_SECRET,       // only server-side
    public: {
      apiUrl: process.env.NUXT_API_URL       // exposed to client
    }
  }
});

// Component
<script setup>
const config = useRuntimeConfig()
const apiUrl = config.public.apiUrl
</script>

<template>
  <p>API: {{ apiUrl }}</p>
</template>
Hire Now!

Need Help with Nuxt Development ?

Work with our skilled nuxt developers to accelerate your project and boost its performance.
**Hire now**Hire Now**Hire Now**Hire now**Hire now