{"id":13493232,"url":"https://github.com/bahmutov/as-a","last_synced_at":"2025-09-29T01:30:35.801Z","repository":{"id":41132158,"uuid":"51475301","full_name":"bahmutov/as-a","owner":"bahmutov","description":"Runs a given command with additional environment settings for simple local development","archived":false,"fork":false,"pushed_at":"2024-09-04T15:00:10.000Z","size":418,"stargazers_count":66,"open_issues_count":3,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-27T20:44:25.538Z","etag":null,"topics":["environment","environment-variables","shell","utility"],"latest_commit_sha":null,"homepage":"https://youtu.be/GyjCGKzFjWA","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bahmutov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-02-10T21:54:39.000Z","updated_at":"2024-11-14T10:41:02.000Z","dependencies_parsed_at":"2024-09-05T19:11:50.829Z","dependency_job_id":"c98b51fe-46a6-46cd-bfa1-75004c6e5fcd","html_url":"https://github.com/bahmutov/as-a","commit_stats":{"total_commits":41,"total_committers":1,"mean_commits":41.0,"dds":0.0,"last_synced_commit":"4577b89cb525b103e3865399e51d87560e45a8da"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fas-a","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fas-a/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fas-a/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fas-a/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bahmutov","download_url":"https://codeload.github.com/bahmutov/as-a/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234575266,"owners_count":18854927,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["environment","environment-variables","shell","utility"],"created_at":"2024-07-31T19:01:13.356Z","updated_at":"2025-09-29T01:30:30.513Z","avatar_url":"https://github.com/bahmutov.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# as-a\n\u003e Runs a given command with additional environment settings for simple local development\n\n[![NPM][as-a-icon] ][as-a-url]\n\n[![ci status][ci image]][ci url]\n[![semantic-release][semantic-image] ][semantic-url]\n\n`as-a` = run \"as a\" ...\n\n- 📺 Watch [Use Utility as-a To Load Multiple Secrets And Pass To Cypress](https://youtu.be/GyjCGKzFjWA) to see how I pass multiple values via environment variables when launching Cypress test runner.\n- 📺 Watch [Inject Entire Objects Into Cypress Tests Using as-a Utility](https://youtu.be/dxGhIvFNm4I)\n\n## Install\n\n    npm install --global as-a\n\nYou can run this tool without installing it\n\n    npx as-a [section name] [command ...]\n\nYou 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.\n\n    npm i -D as-a\n    npx as-a [section name] [command ...]\n\n## Use\n\nCreate a file in your user's home directory `.as-a.ini`\n\n    touch ~/.as-a.ini\n\nCreate separate sections for groups of environment settings. For example\n\n```ini\n; this is a test section\n[test]\nname=test\nwhy=just because\n```\n\nNow you can run any command (with arguments) and add the section as environment variables.\n\n    $ npm run env | grep why\n    --- nothing ----\n    $ as-a test npm run env | grep why\n    why=just because\n\nRecommended to keep private settings for DEV urls, secrets, etc.\n\n## Multiple profiles\n\nYou can even use settings from multiple groups of settings using comma-separated list\n\n```ini\n[DEV]\nusername=tester\npassword=pass1234\n[redis]\nREDIST_HOST=localhost:4534\n```\n\n    as-a DEV,redis node index.js\n\n## Current folder\n\nA good practice for me was naming a section after the folder name. For example, if the INI file has the following:\n\n```ini\n[my-server-repo]\nDB_USERNAME=user1234\n```\n\nThen we can inject the variables by running in the folder \"my-server-repo\" using \".\"\n\n```\n/my/folders/my-server-repo: $ as-a . node ./start\n# injects section \"my-server-repo\"\n```\n\n## Use case\n\nRead how to run a Redis server inside the Docker container using `as-a` in this\n[gist](https://gist.github.com/bahmutov/f09b5895f5bb0f2a13f5).\n\n## Secret folder\n\nTo better separate secrets from user home folder, you can place the `.as-a.ini` file\ninto subfolder `~/.as-a/.as-a.ini`.\n\n## Local file\n\nSometimes it makes sense to have a local file `.as-a.ini` in the project's\nfolder (current working directory) with settings that should override\nany section from the home folder's `.as-a.ini`. Just create such file and use\nit.\n\n**Tip:** when using a local `.as-a.ini` file make sure to `git ignore .as-a.ini` to avoid accidentally committing this file to the repository.\n\nResolution\n\n- local `.as-a.ini` + `~/.as-a.ini` =\u003e combination, local file wins\n- local `.as-a.ini` + `~/.as-a/.as-a.ini` =\u003e combination, local file wins\n- local `.as-a.ini` =\u003e just this file\n- otherwise an error is thrown\n\n\n## Section aliases\n\nJust like you can use multiple sections, the INI sections themselves can have multiple aliases. For example, you can have the same section under two or more names to avoid duplication:\n\n```ini\n; you can use these environment variables by using name \"user\" or \"personal\"\n[user, personal]\nNAME=...\nID=...\n```\n\nThese two commands are equivalent\n\n```shell\n$ as-a user ...\n$ as-a personal ...\n```\n\n## Version\n\nTo see the version of the installed `as-a` run it without arguments\n\n```\n$ as-a\nas-a@2.1.0\n \u003e Runs a given command with additional environment settings\n \u003e for simple local development\nuse    : as-a \u003cenv settings name\u003e [command with options]\nexample: as-a DEV node client.js --request foo\n```\n\n## NPM module API\n\n### getSettings\n\nLoads the specified settings sections and returns merged object\n\n```js\nconst {getSettings} = require('as-a')\n// load sections [db] and [app]\ngetSettings('db,app') // {DB_HOST:...,USERNAME:...}\n```\n\n## Debugging\n\nIf the settings are not applied correctly, run the command with `DEBUG=as-a` variable\n\n```\n$ DEBUG=as-a as-a name command arguments ...\n  as-a loading sections +1ms [ 'name' ]\n  as-a running \"npx\" with extra env keys +0ms [ 'USERNAME', 'PASSWORD' ]\n  ..\n```\n\n## Read\n\n- watch [Use Utility as-a To Load Multiple Secrets And Pass To Cypress](https://youtu.be/GyjCGKzFjWA)\n- [Keep passwords secret in E2E tests](https://glebbahmutov.com/blog/keep-passwords-secret-in-e2e-tests/)\n- recommended to watch [Passing the environment variables to Cypress](https://youtu.be/jAiYePsxPl4)\n\n## Small print\n\nAuthor: Gleb Bahmutov \u0026copy; 2016\n\n- [@bahmutov](https://twitter.com/bahmutov)\n- [glebbahmutov.com](https://glebbahmutov.com)\n- [blog](https://glebbahmutov.com/blog/)\n- [videos](https://www.youtube.com/glebbahmutov)\n- [presentations](https://slides.com/bahmutov)\n- [cypress.tips](https://cypress.tips)\n\nLicense: MIT - do anything with the code, but don't blame me if it does not work.\n\nSpread the word: tweet, star on github, etc.\n\nSupport: if you find any problems with this module, email / tweet /\n[open issue](https://github.com/bahmutov/as-a/issues) on Github\n\n## MIT License\n\nCopyright (c) 2016 Gleb Bahmutov\n\nPermission is hereby granted, free of charge, to any person\nobtaining a copy of this software and associated documentation\nfiles (the \"Software\"), to deal in the Software without\nrestriction, including without limitation the rights to use,\ncopy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n\n[as-a-icon]: https://nodei.co/npm/as-a.svg?downloads=true\n[as-a-url]: https://npmjs.org/package/as-a\n[semantic-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg\n[semantic-url]: https://github.com/semantic-release/semantic-release\n\n[ci image]: https://github.com/bahmutov/as-a/workflows/ci/badge.svg?branch=master\n[ci url]: https://github.com/bahmutov/as-a/actions\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahmutov%2Fas-a","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbahmutov%2Fas-a","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahmutov%2Fas-a/lists"}