1. dotenv-defaults
dotenv... but with defaults!
dotenv-defaults
Package: dotenv-defaults
Created by: mrsteele
Last modified: Mon, 27 Jun 2022 03:43:58 GMT
Version: 5.0.2
License: MIT
Downloads: 4,357,733
Repository: https://github.com/mrsteele/dotenv-defaults

Install

npm install dotenv-defaults
yarn add dotenv-defaults

dotenv-defaults

A dotenv system that supports defaults.

Status

npm
Main
dotenv-vault

Installation

Use the following to install this module:

npm i dotenv-defaults --save

Usage

This module supports all the features from the original dotenv module, so usage should be simple enough:

# .env.defaults, safe to commit
HOST=website.com
[email protected]
# .env, DO NOT COMMIT
HOST=mrsteele.dev

The result

 require('dotenv-defaults').config()

// Or you can also load it directly like this
require('dotenv-defaults/config')

console.log(process.env.HOST)
// Outputs: mrsteele.dev

console.log(process.env.EMAIL)
// Outputs: [email protected]
TypeScript

Since this module does not provide TypeScript Type Definitions if you try to import it like import dotenv from "dotenv-defaults" TypeScript will return an error.

Instead you should load it like this:

 import "dotenv-defaults/config"
CLI

You can also call this module directly when using the node executable.
So, for example if you are running a custom script with node and you want to load your environment variables you can do the following node -r dotenv-defaults/config your-script.js. (When using this method, please make sure that you have installed dotenv-defaults with npm or yarn in the same directory)

Differences

The only thing to note is that the original module supported an options argument in the config function.

This module supports that as well, but there is an added defaults property that can allow you to define where that file is located. An example is shown below:

 // all of these are the default values...
require(`dotenv-defaults`).config({
  path: './.env',
  encoding: 'utf8',
  defaults: './.env.defaults' // This is new
})

License

MIT

Dependencies

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code