You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

dotenv-eval

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

dotenv-eval

Add command substitution to dotenv

0.2.0
latest
Source
npmnpm
Version published
Weekly downloads
1.7K
22.65%
Maintainers
1
Weekly downloads
 
Created
Source

dotenv-eval

dotenv-eval

Dotenv-eval adds command evaluation on top of dotenv. If you find yourself needing to add the output of a command in one of your environment variables, then dotenv-eval is your tool.

Install

# Install locally (recommended)
npm install dotenv-eval --save

Or installing with yarn? yarn add dotenv-eval

Usage

Create a .env file in the root of your project:

GREETING="$(echo hello)"

As early as possible in your application, import and configure dotenv and then eval dotenv:

var dotenv = require('dotenv')
var dotenvEval = require('dotenv-eval')

var myEnv = dotenv.config()
dotenvEval.eval(myEnv)

console.log(process.env)

That's it. process.env now has the evaluated (command substitution) values you defined in your .env file.

Documentation

DotenvEval exposes one function:

  • eval

Eval

eval will evaluate (command substitution) your environment variables.

const dotenv = {
  parsed: {
    BASIC_SUBSTITUTE: '$(echo hello)'
  }
}

const obj = dotenvEval.eval(dotenv)

console.log(obj) // { BASIC_SUBSTITUTE: 'hello' }

Options

ignoreProcessEnv

Default: false

Turn off writing to process.env.

const dotenv = {
  ignoreProcessEnv: true,
  parsed: {
    SHOULD_NOT_EXIST: 'testing'
  }
}
const obj = dotenvEval.eval(dotenv).parsed

console.log(obj.SHOULD_NOT_EXIST) // testing
console.log(process.env.SHOULD_NOT_EXIST) // undefined

FAQ

What rules does the command substitution engine follow?

The substitution engine roughly has the following rules:

  • $(command) will substitute any command inside the $( )
  • \$(command) will escape the $(command) rather than substitute it

You can see a full list of examples here.

CHANGELOG

See CHANGELOG.md

Keywords

dotenv

FAQs

Package last updated on 10 Feb 2022

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