{"id":21177453,"url":"https://github.com/betsol/detect-environment","last_synced_at":"2025-07-09T22:30:46.643Z","repository":{"id":143735487,"uuid":"104983853","full_name":"betsol/detect-environment","owner":"betsol","description":"Detects environment by examining CLI arguments and NODE_ENV","archived":false,"fork":false,"pushed_at":"2017-09-27T08:12:52.000Z","size":8,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-24T06:47:14.055Z","etag":null,"topics":["cli","environment","node-env","nodejs","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/betsol.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}},"created_at":"2017-09-27T07:02:04.000Z","updated_at":"2017-12-08T21:46:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"c73b09df-db9d-4d09-aa75-6f5c23142260","html_url":"https://github.com/betsol/detect-environment","commit_stats":{"total_commits":4,"total_committers":1,"mean_commits":4.0,"dds":0.0,"last_synced_commit":"b185989422097ae05975ed570dffe58819e2373d"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/betsol/detect-environment","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/betsol%2Fdetect-environment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/betsol%2Fdetect-environment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/betsol%2Fdetect-environment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/betsol%2Fdetect-environment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/betsol","download_url":"https://codeload.github.com/betsol/detect-environment/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/betsol%2Fdetect-environment/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262509290,"owners_count":23322014,"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":["cli","environment","node-env","nodejs","typescript"],"created_at":"2024-11-20T17:16:10.607Z","updated_at":"2025-07-09T22:30:46.398Z","avatar_url":"https://github.com/betsol.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# detect-environment\n\n[![npm version](https://badge.fury.io/js/%40betsol%2Fdetect-environment.svg)](https://badge.fury.io/js/%40betsol%2Fdetect-environment)\n\nDetects environment by examining CLI arguments and NODE_ENV.\n\n## Features\n\n- Two detection methods: `CLI` and `NODE_ENV`\n- Detection methods, the order of their use and the list of environments are fully configurable\n- Enables shorthand syntax and environment name aliases\n- Very small module with single dependency\n- Written in TypeScript, shipped with typings\n- Targeted to ES6\n\n\n## Installation\n\n### yarn\n\n`yarn add @betsol/detect-environment`\n\n### npm\n\n`npm i @betsol/detect-environment`\n\n\n## Usage\n\nRequire the module and call it to detect the environment. Pass options to alter the default behavior.\nLibrary will always return the canonical name of the detected environment even if shorthand syntax was used.\n\nThe module will sequentially iterate over various detection methods until environment will be detected,\notherwise it will fallback to default environment.\n\n\u003e The order and availability of detection methods could be configured through `methods` option.\n\n### Detection Methods\n\n#### `CLI`\n\nThis method detects environment by examining the CLI arguments passed to your program.\n\nVarious call formats are possible:\n\n- `$ node app.js --environment=production` — This is the longest \"canonical\" form\n- `$ node app.js --env=production` — Shorthand `\"env\"` argument name could be used\n- `$ node app.js --environment=prod` — Shorthand `\"prod\"` environment name is used\n- `$ node app.js --env=prod` — Both of the above\n- `$ node app.js --production` — Just the canonical name of the environment is used\n- `$ node app.js --prod` — This is the shortest form, nice for development\n\n\u003e Canonical environment names and their aliases could be configured using `environments` option.\n\n#### `NODE_ENV`\n\nThis method examines the value of `NODE_ENV` environment variable.\n\n- `$ NODE_ENV=production app` — Longest \"canonical\" form\n- `$ NODE_ENV=prod app` — Shorthand environment name could be used\n\n\n### Minimal Example\n\n```js\nconst detectEnvironment = require('@betsol/detect-environment');\n\nconst ENVIRONMENT = detectEnvironment();\n\n// ENVIRONMENT = \"development\"\n```\n\n### Default Options Example\n\n```js\nconst detectEnvironment = require('@betsol/detect-environment');\n\nconst ENVIRONMENT = detectEnvironment({\n  environments: {\n    production: {\n      aliases: ['prod']\n    },\n    development: {\n      aliases: ['dev']\n    }\n  },\n  methods: ['CLI', 'NODE_ENV'],\n  defaultEnvironment: 'development'\n});\n\n// ENVIRONMENT = \"development\"\n```\n\n## Options\n\n- `environments` — is map where each key is a canonical environment name, e.g. `prodution`.\n- `environments[].aliases` — is a string array of all shorthand/alternative environment names,\n  e.g.: `['dev', 'develop', 'local']`\n- `methods` — is a prioritized list of methods to use for environment detection.\n  Possible values are: `CLI` and `NODE_ENV`.\n- `defaultEnvironment` — fallback canonical environment name to be used by default, e.g.: `development`.\n\n## Support\n\nIf this library is useful to you, please add a star on [GitHub repository][repo-gh].\n\nThank you!\n\n\n## License\n\n```\nThe MIT License (MIT)\n\nCopyright (c) 2017 Slava Fomin II, BETSOL GROUP FOUNDATION.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n```\n\n  [repo-gh]: https://github.com/betsol/detect-environment\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbetsol%2Fdetect-environment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbetsol%2Fdetect-environment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbetsol%2Fdetect-environment/lists"}