More Premium Hugo Themes Premium Nuxt Themes

Dotenv Module

Loads your .env file into your application context

Dotenv Module

Loads your .env file into your application context

Author Avatar Theme by nuxt-community
Github Stars Github Stars: 495
Last Commit Last Commit: Jan 4, 2024 -
First Commit Created: Dec 18, 2023 -
Dotenv Module screenshot

Overview

The @nuxtjs/dotenv module is a Nuxt.js module that allows you to load variables from your .env file directly into your Nuxt.js application context and process.env. It provides an easy way to manage and access environment variables within your Nuxt.js project.

Features

  • Loads .env file into context options: The module loads variables from your .env file directly into your Nuxt.js application context and process.env.
  • Restrict accessible variables: You can restrict what variables are accessible into the context by passing an only array with the keys you want to allow.
  • Customize .env file path: By default, the module loads the .env file from the root of your project, but you can change the path using the path option.
  • Includes system variables: By default, system variables are ignored, but setting systemvars to true allows your system-set variables to work.
  • Override default .env file name: You can override the default .env file name using the filename option.

Installation

  1. Add @nuxtjs/dotenv as a dependency to your project:
npm install @nuxtjs/dotenv
  1. Add @nuxtjs/dotenv to the buildModules section of nuxt.config.js:
buildModules: [
  '@nuxtjs/dotenv',
]

Note: If you are using a Nuxt version previous than v2.9, you have to install the module as a dependency (without --dev or --save-dev flags) and use the modules section in nuxt.config.js instead of buildModules.

Summary

The @nuxtjs/dotenv module provides a convenient way to load variables from your .env file into your Nuxt.js application context and process.env. It allows you to easily manage environment variables and customize their accessibility within your Nuxt.js project. With features like restricting accessible variables, customizing the .env file path, including system variables, and overriding the default .env file name, this module offers flexibility and ease of use for handling environment variables in Nuxt.js.