GitHunt
NU

nuxt-community/separate-env-module

Tear your variables apart!

Separate env module - Tear your variables apart!

npm version
npm downloads
Circle CI
Codecov
License

Separated environment variables for server and client build

๐Ÿ“– Release Notes

โš ๏ธ With Nuxt v2.13 you might want to use the new runtime config instead of this.

Setup

  1. Add @nuxtjs/separate-env dependency to your project
yarn add @nuxtjs/separate-env # or npm install @nuxtjs/separate-env
  1. Add @nuxtjs/separate-env to the modules section of nuxt.config.js
{
  modules: [
    '@nuxtjs/separate-env'
  ],
  env: {
    // Your environment variables here (see Configuration section below)
  }
}

Configuration

To define environment variables only available on server/client side,
use the env key of your nuxt.config.js and nest the variables
in a server or client object:

{
  env: {
    server: {
      ONLY_SERVER: 'yup',
      DIFFERENT_ON_BOTH: 'server'
    },
    client: {
      ONLY_CLIENT: 'okay',
      DIFFERENT_ON_BOTH: 'client'
    },
    normalEnvVariableThatWillBeAvailableEverywhere: 'Hi'
  }
}

That's it! You are good to go.

Caveats

IMPORTANT: Be aware that server-side means on every first render of your application.
Your secret tokens won't be included anywhere except where you use them

Development

  1. Clone this repository
  2. Install dependencies using yarn install or npm install
  3. Start development server using npm run dev

License

MIT License

Copyright (c) - Nuxt Community

Languages

JavaScript76.6%Vue23.4%

Contributors

MIT License
Created October 13, 2018
Updated August 29, 2025
nuxt-community/separate-env-module | GitHunt