Miss any of our Open RFC calls?Watch the recordings here! »

@sharyn/env

3.5.4 • Public • Published

🌹 @sharyn/env

Deprecated

Use envalid instead. Example:

const envalid = require('envalid')
const pick = require('lodash.pick')
const either = require('@sharyn/util.either')
const swit = require('@sharyn/util.swit')
 
const { email, bool, port, str } = envalid
 
const varDefs = {
  STAGE: str({ choices: ['dev', 'local-prod', 'staging', 'prod'] }),
  TRUE: bool(),
  EMAIL: email({ desc: 'The email of the admin' }),
  PORT: port(),
}
 
const env = envalid.cleanEnv(
  process.env,
  {
    STAGE: varDefs.STAGE,
    ...swit(
      process.env.STAGE,
      ['dev', 'local-prod', pick(varDefs, 'TRUE', 'PORT')],
      ['staging', 'prod', pick(varDefs, 'EMAIL', 'PORT')]
    ),
  },
  { strict: true }
)
 
module.exports = env

Usage

npm install --save-dev @sharyn/env
# or 
yarn add --dev @sharyn/env

@sharyn/env

With @sharyn/env, you can import your environment variables directly:

import { NODE_ENV, PORT, DATABASE_URL } from '@sharyn/env'

This package simply runs dotenv/config and exports process.env for a convenient access.

Just use @sharyn/env in every file that needs access to the environment, and forget about dotenv and process.env completely.

@sharyn/env.check

@sharyn/env.check can also help you validate environment variables.


This package is part of Sharyn, a collection of utilities and helpers.

Keywords

none

Install

npm i @sharyn/env

DownloadsWeekly Downloads

33

Version

3.5.4

License

MIT

Unpacked Size

3.36 kB

Total Files

7

Last publish

Collaborators

  • avatar