Runs a given command with additional environment settings for simple local development
as-a = run "as a" ...
npm install --global as-a
You can run this tool without installing it
npx as-a [section name] [command ...]
You can also install this tool locally as a dev dependency. In that case, it will start faster than using
npx as-a ... without an install.
npm i -D as-a npx as-a [section name] [command ...]
Create a file in your user's home directory
Create separate sections for groups of environment settings. For example
; this is a test section [test] name=test why=just because
Now you can run any command (with arguments) and add the section as environment variables.
$ npm run env | grep why --- nothing ---- $ as-a test npm run env | grep why why=just because
Recommended to keep private settings for DEV urls, secrets, etc.
You can even use settings from multiple groups of settings using comma-separated list
[DEV] username=tester password=pass1234 [redis] REDIST_HOST=localhost:4534
as-a DEV,redis node index.js
A good practice for me was naming a section after the folder name. For example, if the INI file has the following:
Then we can inject the variables by running in the folder "my-server-repo" using "."
/my/folders/my-server-repo: $ as-a . node ./start # injects section "my-server-repo"
Read how to run a Redis server inside the Docker container using
as-a in this
To better separate secrets from user home folder, you can place the
Sometimes it makes sense to have a local file
.as-a.ini in the project's
folder (current working directory) with settings that should override
any section from the home folder's
.as-a.ini. Just create such file and use
~/.as-a.ini=> combination, local file wins
~/.as-a/.as-a.ini=> combination, local file wins
.as-a.ini=> just this file
- otherwise an error is thrown
Author: Gleb Bahmutov © 2016
License: MIT - do anything with the code, but don't blame me if it does not work.
Spread the word: tweet, star on github, etc.
Support: if you find any problems with this module, email / tweet / open issue on Github
Copyright (c) 2016 Gleb Bahmutov
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.