{"id":15405242,"url":"https://github.com/fnando/env_vars-node","last_synced_at":"2025-04-17T00:57:24.270Z","repository":{"id":66031422,"uuid":"158884733","full_name":"fnando/env_vars-node","owner":"fnando","description":"Access environment variables. Also includes presence validation, type coercion and default values.","archived":false,"fork":false,"pushed_at":"2018-11-27T22:01:20.000Z","size":21,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-14T16:12:49.553Z","etag":null,"topics":["12-factor","config","configuration","configuration-management","dotenv","environment-variables","nodejs"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fnando.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2018-11-23T22:58:23.000Z","updated_at":"2018-11-29T19:26:16.000Z","dependencies_parsed_at":"2023-07-18T05:31:08.679Z","dependency_job_id":null,"html_url":"https://github.com/fnando/env_vars-node","commit_stats":{"total_commits":11,"total_committers":1,"mean_commits":11.0,"dds":0.0,"last_synced_commit":"9623fbcb816a06d5dccb368a627a231b70c1ab17"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fenv_vars-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fenv_vars-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fenv_vars-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fenv_vars-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fnando","download_url":"https://codeload.github.com/fnando/env_vars-node/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249295820,"owners_count":21246192,"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":["12-factor","config","configuration","configuration-management","dotenv","environment-variables","nodejs"],"created_at":"2024-10-01T16:15:41.738Z","updated_at":"2025-04-17T00:57:24.253Z","avatar_url":"https://github.com/fnando.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @fnando/env_vars\n\nAccess environment variables. Also includes presence validation, type coercion and default values.\n\n[![Travis-CI](https://travis-ci.org/fnando/env_vars-node.svg)](https://travis-ci.org/fnando/env_vars-node)\n[![NPM package version](https://img.shields.io/npm/v/@fnando/env_vars.svg)](https://www.npmjs.com/package/@fnando/env_vars)\n[![License: MIT](https://img.shields.io/npm/l/@fnando/env_vars.svg)](https://tldrlegal.com/license/mit-license)\n\n## Installation\n\n```\nyarn add -E @fnando/env_vars\n```\n\n## Usage\n\n```js\n// config.js\nimport {env, int, bool, string} from \"@fnando/env_vars\"\n\nconst config = env(({mandatory, optional}) =\u003e {\n  mandatory(\"DATABASE_URL\", string);\n  optional(\"TIMEOUT\", int, 10);\n  optional(\"FORCE_SSL\", bool, false);\n  optional(\"NODE_ENV\", string, \"development\", {aliases: [\"env\"]});\n});\n\nexport default config;\n\n// app.js\nimport config from \"./config\";\nconfig.databaseURL\nconfig.timeout\nconfig.forceSSL\n```\n\nYou can also set arbitrary properties, like the following:\n\n```js\n// config.js\nimport {env, string} from \"@fnando/env_vars\"\nimport redis from \"redis\"\n\nconst config = env(({property, optional}) =\u003e {\n  optional(\"REDIS_URL\", string, \"redis://127.0.0.1\");\n  property(\"redis\", () =\u003e redis.createClient(config.redisURL));\n});\n\n// app.js\nimport config from \"./config\";\nimport {print} from \"redis\";\n\nconfig.redis.set(\"key\", \"value\", print);\nconfig.redis.get(\"key\", print);\n//=\u003e \"value\"\n```\n\n### Missing properties \u0026 assignment\n\nAn exception is thrown for properties that weren't registered:\n\n```js\nconfig.missing\n//=\u003e throws `\"missing\" is not a registered configuration.`\n```\n\nYou're also not allowed to assign properties to the config object.\n\n```js\nconfig.name = \"John\";\n//=\u003e throws `Configuration is read-only (\"name\" was assigned).`\n```\n\n### Acronyms\n\n`@fnando/env_vars` supports a small list of acronyms (words that will be set as uppercased in property names). Words like `URL` and `SSL` will be returned as it is (e.g. `REDIS_URL` will be defined as `config.redisURL`). The full list is available at \u003chttps://github.com/fnando/env_vars-node/blob/master/acronyms.js\u003e. You can add new words to the list by loading `@fnando/env_vars/acronyms` like the following:\n\n```js\nimport {env, string} from \"@fnando/env_vars\"\nimport {acronyms} from \"@fnando/env_vars/acronyms\";\n\nacronyms.push(\"RTSP\");\n\nconst config = env(({optional}) =\u003e {\n  optional(\"RTSP_SERVER\", string, \"rtsp://127.0.0.1\");\n});\n\nconfig.RTSPServer\n```\n\n### Types\n\nYou can coerce values to the following types:\n\n- `string`: Is the default. E.g. `optional(\"name\", string)`.\n- `int`: E.g. `optional(\"timeout\", int)`.\n- `float`: E.g. `optional(\"wait\", float)`.\n- `bool`: E.g. `optional(\"force_ssl\", bool)`. Any of `yes`, `true` or `1` is considered as `true`. Any other value will be coerced to `false`.\n- `array`: E.g. `optional(\"chars\", array())` or `optional(\"numbers\", array(int))`. The environment variable must be something like `a,b,c`.\n\n### Testing\n\nTo stub properties in tests, you can import `stub` and `restore`:\n\n```js\nimport {env, int} from \"@fnando/env_vars\";\nimport {stub, restore} from \"@fnando/env_vars/testing\";\n\nconst config = env(({optional}) =\u003e optional(\"NUMBER\", int, 1234));\nconfig.number\n//=\u003e 1234\n\nstub(config, \"number\", 4321);\nconfig.number\n//=\u003e 4321\n\nrestore();\n\nconfig.number\n//=\u003e 1234\n```\n\n## Development\n\nRun `yarn test` to run the tests.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/fnando/env_vars-node. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.\n\n## License\n\nThe package is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnando%2Fenv_vars-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffnando%2Fenv_vars-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnando%2Fenv_vars-node/lists"}