{"id":22367626,"url":"https://github.com/hugojosefson/env-config","last_synced_at":"2026-01-19T05:33:26.055Z","repository":{"id":38245479,"uuid":"259373402","full_name":"hugojosefson/env-config","owner":"hugojosefson","description":"Reads env variables. Reads files from _FILE variables. Parses any JSON values.","archived":false,"fork":false,"pushed_at":"2024-10-05T11:12:42.000Z","size":392,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-08T11:56:41.415Z","etag":null,"topics":["config","env","environment","environment-variables","hacktoberfest","json","nodejs"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/@hugojosefson/env-config","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/hugojosefson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-27T15:29:45.000Z","updated_at":"2024-10-05T10:11:48.000Z","dependencies_parsed_at":"2023-02-05T07:46:21.875Z","dependency_job_id":null,"html_url":"https://github.com/hugojosefson/env-config","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hugojosefson%2Fenv-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hugojosefson%2Fenv-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hugojosefson%2Fenv-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hugojosefson%2Fenv-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hugojosefson","download_url":"https://codeload.github.com/hugojosefson/env-config/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228164998,"owners_count":17879177,"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":["config","env","environment","environment-variables","hacktoberfest","json","nodejs"],"created_at":"2024-12-04T18:19:36.013Z","updated_at":"2026-01-19T05:33:26.028Z","avatar_url":"https://github.com/hugojosefson.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @hugojosefson/env-config\n\nReads env variables into a config object.\n\n[![Build Status](https://travis-ci.org/hugojosefson/env-config.svg?branch=master)](https://travis-ci.org/hugojosefson/env-config)\n[![npm page](https://img.shields.io/npm/v/@hugojosefson/env-config)](https://npmjs.com/package/@hugojosefson/env-config)\n[![License MIT](https://img.shields.io/npm/l/@hugojosefson/env-config)](https://tldrlegal.com/license/mit-license)\n[![SemVer 2.0.0](https://img.shields.io/badge/SemVer-2.0.0-lightgrey)](https://semver.org/spec/v2.0.0.html)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen)](https://standardjs.com)\n\n## Usage\n\n### Default\n\nSimplest case, using defaults for everything. Uses `process.env` as its\n`source`.\n\n```js\nimport envConfig from '@hugojosefson/env-config'\n\nconst { DB_PORT, DB_USERNAME, DB_PASSWORD } = envConfig()\n```\n\n### Using options, for example to CamelCase key names\n\n```js\nimport envConfig from '@hugojosefson/env-config'\nimport ra from 'ramda-adjunct'\n\nconst transformer = ra.renameKeysWith(camelcase)\nconst { dbPort, dbUsername, dbPassword } = envConfig({ transformer })\n```\n\nFor more options, see [API](#api) below.\n\n## Installation\n\n```bash\nyarn add @hugojosefson/env-config\n\n  # or\n\nnpm install --save @hugojosefson/env-config\n```\n\n### Node.js version\n\n- Node.js `\u003e=8.0.0` for using this package in your app.\n- Node.js `\u003e=13.7.0` for running the developer tools to make changes to this\n  repository.\n\n_Note: If you use Node.js `\u003c8.5.0`, you probably need to\n`const envConfig = require('@hugojosefson/env-config')` instead of `import`._\n\n## Features\n\n### Reads files from `_FILE` vars\n\nIf any environment variable is suffixed with `_FILE`, it reads its value as a\nfile path, and replaces it with the file's contents. Also removes the `_FILE`\nsuffix.\n\nFor example, with an environment like this:\n\n```bash\nDB_PORT=\"5432\"\nDB_USERNAME=\"my_app\"\nDB_PASSWORD_FILE=\"/run/secrets/MY_APP_DB_PASSWORD\"\n```\n\n...and the file `/run/secrets/MY_APP_DB_PASSWORD` containing:\n\n    mNntp6J76p6pkK2tTgw2bEvC\n\n...you will get this JS object as output:\n\n```js\n{\n  DB_PORT: 5432,\n  DB_USERNAME: 'my_app',\n  DB_PASSWORD: 'mNntp6J76p6pkK2tTgw2bEvC'\n}\n```\n\n### Parses any JSON\n\nIf any environment variable _can_ be parsed as JSON, it is. If not, it's still a\nstring.\n\nFor example, number strings are converted to numbers, `\"true\"` and `\"false\"` are\nconverted to the boolean values `true` and `false`, respectively.\n\nIt also supports large JSON objects and JSON arrays.\n\nFor example, with this environment:\n\n```bash\nSERVER='{\"http\":{\"enable\":true,\"port\":3000},\"tls\":{\"enable\":false}}'\nTEXTS='{\"greetings\":[\"Hi!\",\"Hello.\",\"Welcome!\"],\"goodbyes\":[\"So long\",\"farewell\",\"auf Wiedersehen\",\"good night\"]}'\n```\n\n...you will get this resulting JS object as output:\n\n```js\n{\n  SERVER: {\n    http: {\n      enable: true,\n      port: 3000,\n    },\n    tls: {\n      enable: false,\n    },\n  },\n  TEXTS: {\n    greetings: ['Hi!', 'Hello.', 'Welcome!'],\n    goodbyes: ['So long', 'farewell', 'auf Wiedersehen', 'good night'],\n  },\n}\n```\n\n## Parses base64 and hex\n\nIf a string is prefixed with `base64:` or `hex:`, the rest of the string is\nautomatically parsed as such, into a new string. That string may in turn be\nsimilarly encoded, or a JSON string.\n\n## API\n\n\u003c!-- Generated by documentation.js. Update this documentation by updating the source code. --\u003e\n\n### envConfig\n\nParses the source into an object.\n\n#### Parameters\n\n- `source` Source object. _Optional. Default: `process.env`._\n- `keys` Array of keys to use. _Optional. Default: All keys in `source`._\n- `decoders` Array of decoder definitions to attempt to use for decoding each\n  value. Each decoder definition is an object with a property `prefix` whose\n  value is a string, or a property `test` whose value is a function to test\n  whether to use this decoder to process the value. Additionally, each decoder\n  definition has a property `decode` which is a function taking the original\n  value, and returning the decoded value. Alternatively `decodeWithoutPrefix`\n  can be defined, which is called with the original value, just having its\n  prefix chopped off first. _Optional. Default: `defaultDecoders`._\n- `transformers` Array of functions for making any changes to the configuration\n  object afterwards. Will be run in order of appearance. _Optional._\n- `transformer` Alternatively for convenience, a single function for making any\n  change to the configuration object afterwards. _Takes the complete config\n  object as argument, and must return the new/altered config object. Optional._\n- `redactFileContents` Whether to redact contents from files. _Optional.\n  Default: `false`._\n- `readFile` Synchronous function to read contents from a file path. _Optional.\n  Default: `'[redacted]'` if `redactFileContents === true`, otherwise\n  `path =\u003e readFileSync(path, { encoding: 'utf8' })`._\n- `failOnMissingFile` Whether to fail if a file can not be read. If `true`, will\n  throw an error if the path to a `_FILE` can not be read, If `false`, will\n  leave the `_FILE` key as it was. _Optional. Default: `false`._\n\nReturns **any** An object where the values are parsed according to\n\u003ca href=\"#features\"\u003eFeatures\u003c/a\u003e.\n\n### defaultDecoders\n\nDefault decoders, decoding strings prefixed with `base64:` and `hex:` into\nstrings, and `base64binary:` and `hexbinary` into `Buffer`s.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhugojosefson%2Fenv-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhugojosefson%2Fenv-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhugojosefson%2Fenv-config/lists"}