Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

webpod/envapi

Repository files navigation

envapi

An API to interact with environment files

Install

npm install envapi

Usage

import { parse, stringify, config, load, loadSafe } from 'envapi'
const input = `A=A\nFOO=BAR`
const env = parse(input) // { A: 'A', FOO: 'BAR' }
const output = stringify(env) // A=A\nFOO=BAR

parse()

Parse a dotenv string into an object.

const raw = `
A=A
FOO=BAR #comment`
const env = parse(raw) // { A: 'A', FOO: 'BAR' }

stringify()

Stringify an object into a dotenv string.

const env = { A: 'A', FOO: 'BAR' }
const raw = stringify(env) // 'A=A\nFOO=BAR'

load()

Read a dotenv file(s) and parse it into an object. loadSafe() suppresses ENOENT errors.

await fs.writeFile('.env1', 'FOO=BAR')
await fs.writeFile('.env2', 'BAZ=QUX')
const env = load('.env1', '.env2') // { FOO: 'BAR', BAZ: 'QUX' }
const _env = loadSafe('.env.notexists') // {}

config()

Load a dotenv file into process.env.

config('.env1')
process.env.FOO // BAR

License

MIT

About

An API to interact with environment files

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

AltStyle によって変換されたページ (->オリジナル) /