Nuxt
Nuxt

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

December 4, 2025

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 ?

Ready to leverage the power of conversational AI? Start your project with Zignuts expert AI developers.
bg-image
download-image
Company Deck
PDF, 3MB
© 2026 Zignuts Technolab. All Rights Reserved.
branch imagesbranch imagesbranch imagesbranch imagesbranch imagesbranch images