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 🙏

© 2026 – Pkg Stats / Ryan Hefner

sensenv

v1.1.2

Published

Tool to generate env object with intellisense

Readme

sensenv

The purpose of this module is to parse the process.env object and create an env JS object with intellisense on the required env variables, env value getter interface and useful error messages if missing environment variables.


Installation

To install the module add it to the dependencies:

npm install sensenv

Usage

Import the module through the name sensenv

  • CommonJS
const {
    getEnv,
    required
} = require("sensenv");
  • ES6
import {
    getEnv,
    required
} from "sensenv";

Then create the object that gets the required variables:

If the environment variables are:

SOME_VAR=some_value
const env = getEnv({
    SOME_VAR: required
});

console.log(env.SOME_VAR) // Logs "some_value"

intellisense



API

const env = getEnv(envSourceObject, envVariableGetter)

env

The JS object with the desired env variables and values.

This object also include the variables: | Variable | Description | | ------------- | ------------- | | NODE_ENV | With the value of process.env.NODE_ENV | | DEVELOPMENT | If NODE_ENV === "development" | | PRODUCTION | If NODE_ENV === "production" | | TESTING | If NODE_ENV === "test" |

  • Example:

If the environment variables are:

NODE_ENV=development
const env = getEnv({});

console.log(env);
/**
 * Logs {
 *      NODE_ENV: "development"
 *      DEVELOPMENT: true
 *      PRODUCTION: false
 *      TESTING: false
 * }
 * */

envSourceObject

A JS object with the desired variables as keys, and a default value in case the environment variable is missing.

If the default value is the required export, the function to throw an exception listing all required missing environment variables.

  • Example:

If the environment variables are:

SOME_VAR_1=value_one
SOME_VAR_2=value_two
const env = getEnv({
    SOME_VAR_1: required,
    SOME_VAR_2: required,
    SOME_VAR_3: null,
    SOME_VAR_4: undefined,
    SOME_VAR_5: "some_default_string",
});

console.log(env.SOME_VAR_1) // "value_one"
console.log(env.SOME_VAR_2) // "value_two"
console.log(env.SOME_VAR_3) // "null"
console.log(env.SOME_VAR_4) // "undefined"
console.log(env.SOME_VAR_5) // "some_default_string"

If we don't give the required env variables in this case, it will throw an exception with the message:

Missing environment variables: SOME_VAR_1, SOME_VAR_2


envVariableGetter

An optional function that gets a fallback value in case the environment variables is not present directly in the process.env object, and has the following type:

const envVariableGetter = (name: string) => value
  • Example:

If the environment variables are:

SOME_VAR_1=some_value_1
const defaultHolder = {
    SOME_VAR_1: "holder_value_1",
    SOME_VAR_2: "holder_value_2",
}

const envVariableGetter = (name) => defaultHolder[name];

const env = getEnv({
    SOME_VAR_1: required,
    SOME_VAR_2: required,
}, envVariableGetter);

console.log(env.SOME_VAR_1) // "some_value_1"
console.log(env.SOME_VAR_2) // "holder_value_2"

Be careful, as the envVariableGetter will not override an already present value in the process.env object

One of the use cases is if you are working with Create React App, where you need your environment variables to be named with the prefix REACT_APP_ .

Then you can use envVariableGetter to check for the variable with the proper prefix and you can use it like it is not using the prefix (as long as you are not looking for some variable that is already present in the environemnt with the given name):

If the environment variables are:

REACT_APP_SOME_VAR=some_value
const envVariableGetter = (name) => process.env[`REACT_APP_${name}`];

const env = getEnv({
    SOME_VAR: required,
}, envVariableGetter);

console.log(env.SOME_VAR) // "some_value"

In this case process.env.SOME_VAR is undefined, but process.env.REACT_APP_SOME_VAR is present, and parsed correctly.

Typescript

If you need the type of this function, it is also exported from the module:

import { getEnv, required, EnvVarGetter } from "../lib";

const envVariableGetter: EnvVarGetter = (name) => process.env[`TYPES_${name}`];

const env = getEnv({
    SOME_VAR: required,
}, envVariableGetter);

console.log(env.SOME_VAR) // "some_value"