0.1.1 • Published 3 years ago
env-getter v0.1.1
The Problem
repeatedly writing process.env is a very inefficient way to fetch more than one environment variable if want to default the environment variable is dev mode but not in production, use this library to assign conditional default values
usage
- input : pass object into first parameter return whole customized process.env object
import env from 'env-getter'
const { PORT, DB_NAME } = env({
envsForDefault: ['dev','qa'],
defaultValues: {
PORT: 8080,
DB_NAME: 'yourDB'
}
})
// if PORT or DB_NAME is undefined, PORT and DB_NAME will be set to default when process.env equal to dev or qa
- input : pass key into first parameter
return :
process.env[key]
, or default value if it's undefined
const port = env('PORT', 8080)
0.1.1
3 years ago