项目作者: goliatone

项目描述 :
Set env vars before running your program, manage environment and secrets.
高级语言: JavaScript
项目地址: git://github.com/goliatone/envset.git
创建时间: 2015-11-02T00:25:41Z
项目社区:https://github.com/goliatone/envset

开源协议:MIT License

下载


envset

envset runs another program with a custom environment according to values defined in a .envset config file, which follows the ini file format. You can share this file between team members.

Inspired by daemontools‘ tool envdir.

Environment level configuration

Application configuration usually is environment specific and changes between build distributions.

If you follow the 12 factor app guidelines, then you know you should store your configuration in the environment.

By application configuration we mean small and oftentimes sensitive data such as API keys, database credentials. Not all environment configuration is sensitive and are instead build distribution specific values such as the application’s TCP port, base URL to build OAuth callbacks, or logging verbosity.

envset helps you manage and set environment variables for multiple build distributions and share environment variables between team members.

Is as simple as calling:

  1. envset development -- node server.js

Examples

An .envset file could look like this:

  1. [production]
  2. NODE_AWS_SECRET_ACCESS_KEY=FS40N0QY22p2bpciAh7wuAeHjJURgXIBQ2cGodpJD3FRjw2EyYGjyXpi73Ld8zWO
  3. NODE_AWS_ACCESS_KEY_ID=LSLhv74Q1vH8auQKUt5pFwnix0FUl0Ml
  4. NODE_HONEYBADGER_KEY=LCgZgqsxKfhO
  5. NODE_POSTGRES_ENDPOINT=50.23.54.25
  6. NODE_POSTGRES_DATABASE=myproject
  7. NODE_POSTGRES_PSWD=Pa$sW03d
  8. NODE_POSTGRES_USER=myproject
  9. [development]
  10. NODE_AWS_SECRET_ACCESS_KEY=HN5ITok3lDaA1ASHxtEpy1U9XCjZwThmfgoIYZk8bkOqc5yk6sT7AWd3ooNeRFV9
  11. NODE_AWS_ACCESS_KEY_ID=m35W4PGGVZfj1gOxYvztFxBD5F2605B3
  12. NODE_HONEYBADGER_KEY=f3MNPUhZoki6
  13. NODE_POSTGRES_ENDPOINT=localhost
  14. NODE_POSTGRES_DATABASE=postgres
  15. NODE_POSTGRES_PSWD=postgres
  16. NODE_POSTGRES_USER=postgres

To use it, simply prefix the call to your program with envset and the name of the environment:

  1. $ envset development -- node app.js

You can:

  1. [local]
  2. MSG=Hello World
  1. envset local -- env | grep MSG | say

Getting Started

Install the module globally with:

  1. npm install envset -g

This will provide a CLI interface, which can be accessed via terminal:

  1. $ envset

If you have recently installed node or npm and get an EACCES error during installation on envset look at this page about fixing permissions on npm.

Documentation

Commands

If you type envset without arguments it will display help and a list of supported environment names.

.envset file

.envsetrc

You can create an .envsetrc file with configuration options for envset.

The default .envsetrc looks like this:

  1. ;Default environment names
  2. filename=./.envset
  3. exportEnvironment=NODE_ENV
  4. [environments]
  5. names[]=test
  6. names[]=staging
  7. names[]=production
  8. names[]=development

Configuration

Follows rc standards.

Post and pre installation hooks

The package.json file includes two installation live cycle scripts:

postinstall:

Executed after installation of the module. It creates a default .envsetrc config file in the user’s home directory.

postuninstall:

Executed after uninstalling the module. It removes the .envsetrc file created during installation.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

  • 2015-11-02: v0.2.0: Initial npm release.
  • 2015-11-21: v0.3.0: Added ‘—‘ to separate command.
  • 2015-11-23: v0.4.0: Print env if no command provided.
  • 2016-06-14: v0.6.0: Fix update-notifier.
  • 2016-06-14: v0.7.0: Fix postinstall.
  • 2016-06-17: v0.8.0: Remove cruft.
  • 2016-06-23: v0.9.0: Walk directory tree upwards looking for .envset.

TODO

  • Tests
  • Programmatic interface
  • Output to stdout so that we can pipe commands

License

Copyright (c) 2015 goliatone
Licensed under the MIT license.