@marknotton/env
v2.0.0
Published
Add, edit, delete and read variables from any .env file.
Downloads
5,490
Readme
Env
Add, edit, delete and read variables from a .env file.
Installation
npm i @marknotton/env --save-dev
import Env from '@marknotton/env'
Usage
Basic usage
const env = new Env()
You can defined a different .env file by passing in a string that is relative path.
const env = new Env('.env.example')
Methods
Set Variable
Add a variable and value to the .env file. Variable will be created if it isn't found. It will be overwritten if it does exists.
env.set(variable, value)
Delete Variable
Delete variable from .env file.
env.delete(variable)
Toggle Variable
Add a 'true' boolean to the given vairable, or remove it entirely if it's false.
env.toggleBoolean(variable, true) // Add's VARIABLE=true
env.toggleBoolean(variable, false) // Removes VARIABLE=true entirely
Get Variable
Get variable from .env file.
env.get(variable)
Has Variable
Check if a variable exists.
env.has(variable)