Socket
Socket
Sign inDemoInstall

get-env-var

Package Overview
Dependencies
2
Maintainers
5
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    get-env-var

Get environment variable


Version published
Weekly downloads
1
decreased by-85.71%
Maintainers
5
Install size
21.2 kB
Created
Weekly downloads
 

Changelog

Source

[2.0.0] - 2016-03-17

Changed

  • undefined is no longer a supported default value

Added

  • Possibility to supply a function that is applied to the value read from the environment
  • Shorthand methods for reading integer and boolean values

Readme

Source

get-env-var

A little function that reads an environment variable from process.env with support for default values and a optional mapping function applied to the data read from the environment.

It will thrown an exception if key can't be found and no default value is supplied.

build status modules status

npm badge

Example

var getEnvVar = require('get-env-var');

getEnvVar('SOME_VAL', 'defaultValue');
getEnvVar('SOME_INT_VAL', Number.parseInt);
getEnvVar('SOME_INT_VAL', 20, Number.parseInt);

Shorthands

The following shorthand methods currently exists. They have the same API as the generic method. The mapping function is applied to the transformed value.

Boolean

getEnvVar.boolean is a shorthand method that returns true if the value equals 'true' and false in all other cases.

Integer

getEnvVar.integer is a shorthand method that calls parseInt(value, 10).

License

MIT

Keywords

FAQs

Last updated on 17 Mar 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc