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

@rhangai/env-builder

v0.5.2

Published

Create .env files for your projects with a single command

Downloads

17

Readme

Basic usage

Install using yarn add @rhangai/env-builder

Create a template.env

APP_NAME=example-app
APP_PASSWORD={{util.random(16)}}
APP_HOST=myapp.example.com
APP_CONNECTION_URL=http://${APP_HOST}/data

Create a .env.local

APP_HOST=myapp.localhost

Configure it using:

yarn run env-builder generate -t template.env -i .env.local -o .env

The generated output will be

APP_NAME=example-app
APP_PASSWORD=somerandomdata12
APP_HOST=myapp.example.com
APP_CONNECTION_URL=http://myapp.localhost/data

Guide

Now that you know what this library does, let's explain what each flag of the following command

yarn run env-builder generate -t template.env -i .env.local -o .env

The -t/--template [file] flag is the template option, it will use it as a base file to generate your .env, it will be also considered the first input file to set the environment variable values

The -i/--input [file] flag may be used to read and override the variables on the template, it can also have additional variables. You can use this flag multiple times on the same command.

The -o/--output [file] flag is used to write the environment file generated by this command.

The --env-override-prefix <prefix> flag is usually combined when using CI. It allows the variables to be overwritten by environment variables of the same name, but prefixed with prefix.

  • Example: When using --env-override-prefix CI_OVERRIDE_ you can set the env CI_OVERRIDE_APP_NAME=my-ci-app to override the variable APP_NAME

package.json mode

You can simplify the usage of the scripts simply by creating the env-builder entry on the package.json file

{
	"devDependencies": {
		"@rhangai/env-builder": "^0.4.0"
	},
	"scripts": {
		"env": "env-builder generate --package --",
		"env:ci": "env-builder generate --package --env-override-prefix CI_OVERRIDE_ --"
	},
	"env-builder": {
		"template": "env/template.env",
		"output": ".env", // Or array [".env", "output/.env"]
		"local": ".env.local",
		"modes": {
			"dev": ["env/development.env"],
			"prod": ["env/production.env"]
		}
	}
}

And the running yarn env

Context

The default context contains two main variables util and env

You can use it in an expression like:

MY_ENV={{ env.OTHER_ENV + util.random(64) }}

Util:

  • util.random(n, alphabet = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFHIJKLMNOPQRSTUVXYZ_'): Generates a random string of length n
  • util.randomBase64(n): N random bytes, base64 encoded
  • util.randomUrlSafeBase64(n): N random bytes, base64 encoded url safe
  • util.randomHex(n): N random bytes, hex encoded