npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mondora/env

v1.3.0

Published

A better way to retrieve environment variables

Downloads

192

Readme

Package Version Build Status Coverage Status Dependencies Status Dev Dependencies Status

env

A better way to retrieve environment variables in nodejs.

Features:

  • set defaults for environment variables
  • set defaults for environment variables only when NODE_ENV != production
  • throw an error if a required environment variable is not set
  • parse environment variables before returning them (eg, parse a base64 string into a Buffer)
  • get environment variables from a different source than process.env
  • for TypeScript, get the correct type information for the variable

Install

yarn add @mondora/env

Usage

import env from "@mondora/env";

export const REQUIRED = env("REQUIRED", { required: true });
export const REQUIRED_ONLY_IN_PRODUCTION = env("REQUIRED_ONLY_IN_PRODUCTION", {
  required: true,
  nonProductionDefault: "DEFAULT"
});
export const NON_REQUIRED = env("NON_REQUIRED");
export const WITH_DEFAULT = env("WITH_DEFAULT", { default: "DEFAULT" });
// PARSED is a Buffer
export const PARSED = env("TO_BE_PARSED", {
  required: true,
  parse: value => Buffer.from(value)
});

API

env(name, options)

Retrieves the specified environment variable.

Arguments
  • name string required: name of the environment variable to retrieve
  • options object:
    • required boolean: marks the variable as required. Ie, if the variable is not set, an error is thrown
    • nonProductionDefault boolean: makes a required variable only required when NODE_ENV == production, while giving it a default value otherwise
    • default string: a default value for the variable if it's not set
    • parse function: a function to transform the value of the variable (a string) into whatever before it's returned by env. The function is called only when a value or a default value for the variable was set
Returns

The value of the environment variable, parsed by the options.parse function if specified.

setInputSource(inputSource)

Sets the input source from which environment variables are retrieved (the default input source is process.env).

Arguments
  • inputSource (string, string) map required: custom input source
Returns

Nothing.

Develop

To get started developing the library, clone the project and install dependencies with yarn. Then you can either:

  • yarn test: runs tests
  • yarn test --watch: runs tests, re-runs them on code changes
  • yarn coverage: runs tests, measures code coverage
  • yarn lint: runs code linters (prettier + tslint)
  • yarn prettify: formats code with prettier
  • yarn compile: compiles the project

NOTE: this project uses prettier to enforce code formatting. Installing the prettier extension for your editor of choice is highly recommended.

Release

  • Run npm version x.x.x to bump a new version of the package. The command will set the specified version number in package.json, commit the change, tag the commit with vx.x.x

  • Push the commit and the tag to github: git push --tags origin master

  • If linting and automated tests pass, the module will automatically be published to npm

Note: you can use convenience commands npm version major, npm version minor, npm version patch to bump the consecutive major / minor / patch version of the package.