Giter Site home page Giter Site logo

node-getenv's Introduction

Get and parse environment variables more easily.

npm i node-getenv --save
const env = require('node-getenv')

// PORT=8080 node index.js
const port = env.getNum('PORT')  // 8080 (number)


// CONSUMER_ON=on node index.js
env.getBool('CONSUMER_ON')  // true

// node index.js
env.getNum('CONCURRENCY', 4)  // 4 (default value)

// node index.js
env.requireNum('CONCURRENCY')   // throw error
env.requireNumOrExit('CONCURRENCY')   // log error, then process exit

getNum(key, defaults)

Get environment variate in number type.

If the environment variate is undefined or not a valid number, return the default value.

getStr(key, defaults)

Get environment variate in string type.

If the environment variate is undefined, return the default value.

getBool(key, defaults)

Get environment variate in boolean type, supported values without case sensitive:

  • Truly: true, yes, on, open, t, y, 1.

  • Falsely: false, no, off, close, f, n, 0.

If the environment variate is undefined or unsupported, return the default value.

bindEnv(defaultValues)

Bind environment variates with default values, then returns them. It has no effect on real environmental variables (in process.env).


License: MIT

node-getenv's People

Contributors

bin-huang avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.