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

@focus21/env

v4.3.0

Published

Load environment variables from env files.

Downloads

44

Readme

@focus21/env

Load environment variables from env files.

[[TOC]]

Usage

Installation:

pnpm add --save @focus21/env

Load env files from .env and .local.env and run my-command:

focus21-env .env my-command

Env File Syntax

Supports similar syntax to dotenv-expand, with a few additions and alterations.

Variables are defined linearly:

FOO="BAR"
BAZ="${FOO}"
FOO="QUX"

# Final values:
# BAZ="BAR"
# FOO="QUX"

Variables can also reference themselves, allowing setting default values for variables only if they aren't set:

FOO="${FOO:-default value}"
# FOO="default value"

Local Env Files

Local env files are automatically loaded by default:

# Loads both vars.env and vars.local.env
focus21-env vars.env my-command

Local env vars override regular env vars.

To disable loading the local env file, use --no-local:

focus21-env --no-local vars.env my-command

To duplicate all variables, set them to lowercase, and add TF_VAR_ for Terraform:

focus21-env --add-tf-var-prefix vars.env terraform ...

To add the special $DOCKER_HOST_USER environment variable:

focus21-env --add-docker-host-user vars.env my-command

The $DOCKER_HOST_USER environment variable can be used to share permissions between the current user and the Docker user.

Advanced Env File Syntax

Some features, such as quotation and escaping, are borrowed from sh/Bash. This allows shell files with only variables and quotes to be used.

This is markedly different than other Javascript env file tools as well as docker compose, so it's suggested just to use double quotes around every variable and to use backslashes when characters need to be escaped. This format is more widely supported.

The double quote/backslash format is used here for displaying final values.

# Spaces end variables unless if they are quoted or escaped.
# Mutliple variables can be set on the same line in this way:
SAMELINE_1="my var 1" SAMELINE_2="my var 2"
# Values:
# SAMELINE_1="my var 1"
# SAMELINE_2="my var 2"

# These are the same: FOO, "FOO", 'FOO'.
UNQUOTED=FOO
# Value: UNQUOTED="FOO"

# By using single quotes, dollar signs aren't interpretted as variable references.
# Using single quotes also escapes double quotes.
SINGLE_QUOTED='"${UNQUOTED}"'
# Value: SINGLE_QUOTED="\"${UNQUOTED}\""

# However, using double quotes, dollar signs are still interpretted normally.
# Using double quotes also escapes single quotes.
DOUBLE_QUOTED="'${UNQUOTED}'"
# Value: DOUBLE_QUOTED="'FOO'"

# Multiple quotes can be used in one variable:
MULTIPLE_QUOTES="FOO"'BAR'
# Value: MULTIPLE_QUOTES="FOOBAR"

# Dollar signs can also be escaped in this way.
# This works unquoted, with single quotes, and with double quotes.
ESCAPED=\${UNQUOTED}
# Value: ESCAPED="${UNQUOTED}"

# Multiline variables can be set with quotes or backslashes:
MULTILINE="FOO
BAR"
# Value: MULTILINE="FOO\nBAR"

# The "export" keyword is also ignored:
export EXPORTED=FOO
# Value: EXPORTED="FOO"