Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mrsteele/dotenv-defaults
dotenv... but with defaults!
https://github.com/mrsteele/dotenv-defaults
defaults dotenv environment environment-variables
Last synced: 19 days ago
JSON representation
dotenv... but with defaults!
- Host: GitHub
- URL: https://github.com/mrsteele/dotenv-defaults
- Owner: mrsteele
- License: mit
- Created: 2018-04-05T15:02:29.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T07:14:47.000Z (almost 2 years ago)
- Last Synced: 2024-11-14T13:31:31.080Z (28 days ago)
- Topics: defaults, dotenv, environment, environment-variables
- Language: JavaScript
- Size: 524 KB
- Stars: 76
- Watchers: 2
- Forks: 8
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - dotenv-defaults - A dotenv system that supports defaults. (Backend frameworks & libraries)
- awesome - dotenv-defaults - A dotenv system that supports defaults. (Backend frameworks & libraries)
README
# dotenv-defaults
A dotenv system that supports defaults.
### Status
![npm](https://img.shields.io/npm/v/dotenv-defaults.svg)
[![Main](https://github.com/mrsteele/dotenv-defaults/actions/workflows/main.yml/badge.svg)](https://github.com/mrsteele/dotenv-defaults/actions/workflows/main.yml)
[![dotenv-vault](https://badge.dotenv.org/works-with.svg?r=3)](https://www.dotenv.org/get-started?r=3)### Installation
Use the following to install this module:
```
npm i dotenv-defaults --save
```### Usage
This module supports all the features from the original [dotenv](https://www.npmjs.com/package/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
```js
require('dotenv-defaults').config()// Or you can also load it directly like this
require('dotenv-defaults/config')console.log(process.env.HOST)
// Outputs: mrsteele.devconsole.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:
```typescript
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:
```js
// all of these are the default values...
require(`dotenv-defaults`).config({
path: './.env',
encoding: 'utf8',
defaults: './.env.defaults' // This is new
})
```### License
MIT