Socket
Book a DemoInstallSign in
Socket

dotenvrc

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dotenvrc

Read .envrc

1.0.1
latest
Source
npmnpm
Version published
Weekly downloads
1.1K
105.06%
Maintainers
1
Weekly downloads
 
Created
Source

dotenvrc

dotenvrc loads environment variables from a .envrc file into process.env.

Motivation

In short, I wanted jest to use environment variables written in a .envrc.

At the writing moment, jest seems to run in a sandboxed environment, i.e. it omits runtime environment variables. Since I'm a big fan of The Twelve-Factor App and direnv, I wanted to keep the single source of truth theory.

Goal

To have the same result of what direnv does in popular and/or realistic use cases.
In this sense, function or shell command execution would be out of support.

Features

  • local variable assignment
  • Supports export
  • Supports export -n (un-export)
  • Supports several backslash notations
    • \xXX: ASCII hex code
    • \uXXXX: 4 digits unicode
    • \UXXXXXXXX: 8 digits unicode
    • \n, \r, \t, \v, \b, \a
  • Supports parameter expansion
    • $VAR
    • ${VAR}
  • Especially treats $PWD. $PWD is expanded to the directory where .envrc found.

Not supported

  • Other than a simple variable assignment and export.
    • Shell command execution
    • Arithmetic expansion
    • Shell history expansion
    • A series of variable calculation e.g. ${#var}, ${var:-val}, etc.

Install

npm install dotenvrc

Usage

To inject .envrc content into process.env, simply:

require('dotenvrc');

If you have .env file instead of .envrc, the following might work for you. (It might not since the Parsing rules are different.)

require('dotenvrc/dotenv').inject()

Example .envrc file

# Firebase/GCP
export BOTO_CONFIG=$PWD/.boto
export GOOGLE_APPLICATION_CREDENTIALS=$PWD/secret/goog-credencials.json

# Cloud Datastore emulator
PORT=18081
export DATASTORE_EMULATOR_PORT=$PORT
export DATASTORE_EMULATOR_HOST=http://localhost:$PORT

LICENSE

MIT

Keywords

direnv

FAQs

Package last updated on 18 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.