← 全部工具

env-cmd

热度 65 更新于 开发与构建

Executes a command using the environment variables in an env file

npmauto-collected

安装

npm
npm install -g env-cmd

通过 npm 安装。

env-cmd

A simple node program for executing commands using an environment from an env file.

💾 Install

npm install env-cmd or npm install -g env-cmd

⌨️ Basic Usage

Environment file ./.env

# This is a comment
ENV1=THANKS
ENV2=FOR ALL
ENV3=THE FISH

Package.json

{
  "scripts": {
    "test": "env-cmd -- mocha -R spec"
  }
}

Terminal

./node_modules/.bin/env-cmd -- node index.js

Using custom env file path

To use a custom env filename or path, pass the -f flag. This is a major breaking change from prior versions < 9.0.0

Terminal

./node_modules/.bin/env-cmd -f ./custom/path/.env -- node index.js

📜 Help

Usage: env-cmd [options] -- <command> [...args]

Options:
  -v, --version                 output the version number
  -e, --environments [envs...]  The rc file environment(s) to use
  -f, --file [path]             Custom env file path or .rc file path if '-e' used (default path: ./.env or ./.env-cmdrc.(js|cjs|mjs|json))
  -x, --expand-envs             Replace $var and ${var} in args and command with environment variables
  --recursive                   Replace $var and ${var} in env file with the referenced environment variable
  --fallback                    Fallback to default env file path, if custom env file path not found
  --no-override                 Do not override existing environment variables
  --silent                      Ignore any env-cmd errors and only fail on executed program failure.
  --use-shell                   Execute the command in a new shell with the given environment

-h, --help display help for command