Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

getenv

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

getenv

Get and typecast environment variables.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
948K
increased by6.03%
Maintainers
1
Weekly downloads
 
Created

What is getenv?

The 'getenv' npm package is a utility for safely and easily accessing environment variables in Node.js applications. It provides a straightforward API to retrieve environment variables with type safety and default values.

What are getenv's main functionalities?

Get a string environment variable

This feature allows you to retrieve a string environment variable. If the variable is not set, it will throw an error.

const getenv = require('getenv');
const dbHost = getenv('DB_HOST');

Get a string environment variable with a default value

This feature allows you to retrieve a string environment variable and provide a default value in case the variable is not set.

const getenv = require('getenv');
const dbHost = getenv('DB_HOST', 'localhost');

Get an integer environment variable

This feature allows you to retrieve an integer environment variable. If the variable is not set or cannot be converted to an integer, it will throw an error.

const getenv = require('getenv');
const port = getenv.int('PORT');

Get an integer environment variable with a default value

This feature allows you to retrieve an integer environment variable and provide a default value in case the variable is not set or cannot be converted to an integer.

const getenv = require('getenv');
const port = getenv.int('PORT', 3000);

Get a boolean environment variable

This feature allows you to retrieve a boolean environment variable. If the variable is not set or cannot be converted to a boolean, it will throw an error.

const getenv = require('getenv');
const isProduction = getenv.bool('IS_PRODUCTION');

Get a boolean environment variable with a default value

This feature allows you to retrieve a boolean environment variable and provide a default value in case the variable is not set or cannot be converted to a boolean.

const getenv = require('getenv');
const isProduction = getenv.bool('IS_PRODUCTION', false);

Other packages similar to getenv

Keywords

FAQs

Package last updated on 09 Oct 2019

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc