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

@camsmith145/env

v1.0.2

Published

0-dependency environment variable management in NodeJS

Downloads

5

Readme

env

Simple, predictable, 0-dependency environment variable management tool for NodeJS, written in Typescript and compiled to es3 for high compatibility.

npm: license David: dependencies Travis: build

The env npm package has fallen into disrepair and destitution, and unfortunately the creator appears unresponsive to pull requests that would address the open issues. This is my solution.

Installation

$ npm i @camsmith145/env

or

$ yarn add @camsmith145/env

Usage

Import environment variables from a json file or an exported js object. The package exports a function which accepts the path to a file.

const {env} = require( '@camsmith145/env' )
env() /* Looks for file named '.env' in process.cwd() */
env('./path/to/file') /* Resolves './path/to/file' in relation to process.cwd() and tries to parse file content */

Parameters

| Parameter | Type | Description | | :-------- | :-------|:----------------------------------------- | | path | string | undefined | Absolute or relative path to a file. Defaults to ./.env | | options | Object | A few modifications to the behavior |

Path Resolution

| Base of path Parameter Value | Method of import | Expected File Content | | :----------------------------- | :----------------------------------------- |:---------------------- | | undefined | JSON.parse(/* content of ./.env */) | Serialized JSON object | | .env | JSON.parse(/* content of ./.env */) | Serialized JSON object | | .env.json | JSON.parse(/* content of ./.env.json */) | Serialized JSON object | | .env.js | JSON.parse(/* content of ./.env.js */) | JS module exports Object |

Options Object

| Property | Type | Default | Description | | :----------------- | :---------------------| :------ |:----------------------------------------- | | ignoreErrors | boolean | undefined | false | Do not throw an Error if verification of variable assignment to process.env[name] fails. | | yieldExisting | boolean | undefined | false | Do not overwrite existing environment variables of the same name. (Sets ignoreErrors to true) | | suppressWarnings | boolean | undefined | false | When ignoreErrors is true, do not print a warning message to the console if verification of assignment to process.env[name] fails.|

Value Serialization

Values assigned to properties of process.env may only be strings. Therefore, any properties within the env file are serialized using JSON.stringify prior to property assignment.

Values that are number, Object, Array should be de-serialized upon access using parseInt(n, radix), JSON.parse, etc.

Values that are Date should be reconstructed using new Date(process.env[key]).

Example

In ./config/test.env :

{
    "variable_name": {
        "key": "value"
    }
}
/* index.js */
const {env} = require( '@camsmith145/env' )
env('./config/test.env')

const myObject = JSON.parse(process.env.variable_name)

console.log(myObject.key) // 'value'

MIT Licensed