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

enveloped

v0.7.3

Published

Extended .env parser

Downloads

2

Readme

MPL 2.0 License LinkedIn


Enveloped is an alternative for dotenv, more feature-rich out of the box, with pretty simple configurations.

Requirements

At the moment, Enveloped it's a zero-dependencies package.

The .env file must be in JSON

Installation and usage

In an initialized project, run:

npm i enveloped

Then, on the main file, add this lines:

import enveloped from "enveloped";
enveloped.init();

I strongly recommend to put them at the top of all.

Now, every time you need an env variable, use the process.var function:

/* .env content
{
	"CURRENT": {
		"STAGE": "testing"
	}
}
*/

let envStage1 = process.var("CURRENT.STAGE");
console.log(envStage1); //-> testing

// Also valid

envStage = process.var("CURRENT").STAGE;
const { STAGE } = process.var("CURRENT");

Configuration

You can pass a custom configuration through enveloped.init(config), where config is an object with:

  • rootPath: directory path where the .env file/s are located. (default: process.cwd())
  • filename: JSON env file name. (default: .env)
  • type: if filename is not supplied, this property will load append to the file name a type. It's a nice-to-have when working with different env files, depending on the stage. (default: empty string) (example: type: "development", loaded file: .env.development)
  • secretKey: the secret key used to encrypt the .env content. It must have only 32 characters (default: it generates a random on initialization).
  • debugMode: if something is not working correctly, this mode will output some help logs to the console. (default: false)

All of this properties are optional. It's important to notice that type will be ignored if filename is supplied.

How it works?

When you call enveloped.init(), the script will:

  1. Merge the configs, in case you supplied a custom one.
  2. Setup debugMode if it's true.
  3. Configure the process node object, adding the var function.
  4. Setup the secret key for the encryption.
  5. Get, validate and parse the env file.
  6. Encrypt a minified version of the env file to a hash.
  7. Save the hash in a env variable called NODE_ENVELOPED.

As you can see, there will only be one env variable, containing a hash.

Now, every time you call process.var("<varName>"), it will:

  1. Read the NODE_ENVELOPED hash.
  2. Decrypt it and convert it to an object.
  3. Search the var.
  4. Return the value if it finds it, or null if not.

Of course, the varName can be chained with dots like: "KEY.CHAINED", to refer a nested key.

For an in-depth guide or reference, you can visit the Wiki.

Licence

Enveloped is under Mozilla Public Licence 2.0 so, obviously, it is open-source. More info at Mozilla MPL 2.0


Made by Juan Saez