dotenv-defaults
dotenv... but with defaults!
Last updated 10 months ago by mrsteele .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install dotenv-defaults 
SYNC missed versions from official npm registry.

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=test@email.com
# .env, DO NOT COMMIT
HOST=mrsteele.dev

The result

// ESM (Node.js 18+)
import { config } from 'dotenv-defaults'
config()

// Or load it directly like this
import 'dotenv-defaults/config'

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

console.log(process.env.EMAIL)
// Outputs: test@email.com
TypeScript

This module now includes full TypeScript type definitions and works seamlessly with TypeScript:

import { config, parse, type ConfigOptions } from 'dotenv-defaults'

// Or load directly
import 'dotenv-defaults/config'

const options: ConfigOptions = {
  path: './.env',
  defaults: './.env.defaults'
}

config(options)
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 --import 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)

Note: For Node.js versions that don't support --import, you can use node --loader dotenv-defaults/config your-script.js

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:

// ESM
import { config } from 'dotenv-defaults'

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

License

MIT

Current Tags

  • 6.0.0                                ...           latest (10 months ago)

18 Versions

  • 6.0.0                                ...           10 months ago
  • 5.0.2                                ...           4 years ago
  • 5.0.1                                ...           4 years ago
  • 5.0.0                                ...           5 years ago
  • 3.0.2                                ...           5 years ago
  • 4.0.0                                ...           5 years ago
  • 3.0.1                                ...           5 years ago
  • 3.0.0                                ...           5 years ago
  • 2.0.2                                ...           5 years ago
  • 2.0.1                                ...           6 years ago
  • 2.0.0                                ...           6 years ago
  • 1.1.1                                ...           7 years ago
  • 1.1.0                                ...           7 years ago
  • 1.0.3                                ...           7 years ago
  • 1.0.2                                ...           8 years ago
  • 1.0.1                                ...           8 years ago
  • 1.0.0                                ...           8 years ago
  • 0.0.1                                ...           9 years ago
Maintainers (1)
Downloads
Total 76
Today 0
This Week 1
This Month 40
Last Day 0
Last Week 17
Last Month 17
Dependencies (1)
Dev Dependencies (3)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE