Cross-platform environment variables
Zoo is the easiest way to set cross-platform environment variables for your app. It is a combination of two great libraries, cross-env and dotenv, and lets you load variables from a
.env file or passed as arguments. It is built in and runs on Node, but it can be used to set environment variables in any subprogram (such as BASH).
zoo is run, your environment variables are injected directly into a spawned process, and your variables are guaranteed to be there when you need them. Works on both unix and windows machines.
Warning: It's never a good idea to commit your
.envfiles to source control!
As part of the Twelve-Factor App methodology, you should be using environment variables. Setting them in your production app is easy if you're using Heroku or similar services, but it can be a pain to deal with on your local machine.
Zoo lets you set up all your variables for dev/testing in a simple and consistent way throughout your team. It can also be great if you are using something like transform-inline-environment-variables to inline values for AWS Lambda functions or similar.
# use globallynpm install zoo -g# or keep it localnpm install zoo --save-dev
To get started, simply run
zoo followed by your command. For example, running
zoo node index.js will take the environment variables from
.env and inject them into the Node process, giving you access to them with
.env file should be in the form of
NAME=VALUE with one variable per line, and should be in the root directory of your project. It should be ignored from your source control.
NAME=Tyrion LannisterSTRONGHOLD=Casterly Rock
If you specify variables command-style, simply put them after the
zoo command with a space between multiple variables. Variables with spaces or special characters should be enclosed in quotes.
zoo NODE_ENV=production NAME="Tyrion Lannister" node index.js
If you use
require('zoo') in your app instead of using the CLI, it will register the environment variables as early as possible. This method works but is not recommended.
All existing environment variables will be preserved. If you specify a variable that already exists in the environment, it will be skipped. This can be overridden with the
--force flag as seen below.
zoo PWD=/ --force node index.js
If you want to specify a custom location for your environment file, you can do so with the
--zoofile flag. Note that an error will be thrown and the process will exit if the custom file is not found.
zoo --zoofile ../.environment-vars node index.js
Get the variables from a file without modifying the environment.
file - The filename of your environment variables file.
Parses variables in the