Skip to content

ltv/env

Repository files navigation

env

NodeJS safe environment parser. Compatible with TypeScript.

In this version,

  • I have removed dotenv support. If you want to use dotenv, please use the previous version. Otherwise, you should install the dotenv package yourself.
  • I have removed the lodash.has and lodash.trim dependencies, and the package size has been reduced. There is no dependency anymore.

Features

  • Safe environment parser
  • Compatible with TypeScript

With typescript, if you're using are not mentioning the default value, the return type will be T | undefined. Otherwise, the return type will be T.

e.g.

const foo = env.string('FOO') // foo: string | undefined
const bar = env.string('BAR', 'bar') // bar: string

Installation

npm install @ltv/env

Usage

const env = require('@ltv/env')
import env from '@ltv/env'

env.string

env.string(key: string, defaultValue?: string): string

env.int

env.int(key: string, defaultValue?: number): number

env.float

env.float(key: string, defaultValue?: number): number

env.bool

env.bool(key: string, defaultValue?: boolean): boolean

env.array

env.array(key: string, defaultValue?: string[]): string[]

env.json

env.json(key: string, defaultValue?: object): object

env.date

env.date(key: string, defaultValue?: Date): Date