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

processenv

v3.0.9

Published

processenv parses environment variables.

Downloads

103,153

Readme

processenv

processenv parses environment variables.

Status

| Category | Status | | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | | Version | npm | | Dependencies | David | | Dev dependencies | David | | Build | GitHub Actions | | License | GitHub |

Installation

$ npm install processenv

Quick start

First you need to integrate processenv into your application:

const { processenv } = require('processenv');

If you use TypeScript, use the following code instead:

import { processenv } from 'processenv';

Then, to parse an environment variable, call the processenv function and provide the name of the environment variable you would like to parse:

const port = processenv('PORT');

Please note that the value is automatically converted to the appropriate data type, e.g. a number. This also works for stringified JSON objects, in case you want to store complex configuration data inside an environment variable.

Using default values

If you want to provide a default value, you may add it as a second parameter. This also works for booleans and all other types. If neither the environment variable nor the desired default value are set, processenv returns undefined:

const port = processenv('PORT', 3000);
const user = processenv('USER', 'Jane Doe');
const isRoot = processenv('ROOT', true);

Alternatively, you may also provide a function which returns the default values. This is useful, e.g. if you want to lazily evaluate a value:

const port = processenv('PORT', () => 3000);

If you want to use an asynchronous function, please note that you must await the call to processenv:

const port = await processenv('PORT', async () => 3000);

Using the ?? operator

Instead of providing a second parameter, you may use the ?? operator to handle default values:

const isRoot = processenv('ROOT') ?? true;

Please note that this is only true if you are using the ?? operator. If you are using the old-style || operator instead, the previous line always returns true, no matter what the actual value of the ROOT environment variable is. To avoid this problem, either use the ?? operator or use the previously shown syntax using a second parameter to provide a default value.

Getting all environment variables

If you want to get all environment variables at once, omit the name and simply call processenv. The values will all be parsed, but you can not specify default values.

const environmentVariables = processenv();

Running quality assurance

To run quality assurance for this module use roboter:

$ npx roboter