{"id":18874249,"url":"https://github.com/chrisandrews7/middy-env","last_synced_at":"2025-04-14T16:21:07.975Z","repository":{"id":47660167,"uuid":"184878218","full_name":"chrisandrews7/middy-env","owner":"chrisandrews7","description":"Environment variable middleware for the middy framework","archived":false,"fork":false,"pushed_at":"2021-09-09T21:09:46.000Z","size":333,"stargazers_count":3,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T05:05:25.618Z","etag":null,"topics":["environment-variables","middleware","middy","serverless"],"latest_commit_sha":null,"homepage":"","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/chrisandrews7.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2019-05-04T09:56:57.000Z","updated_at":"2022-04-29T07:11:20.000Z","dependencies_parsed_at":"2022-09-04T15:50:59.236Z","dependency_job_id":null,"html_url":"https://github.com/chrisandrews7/middy-env","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisandrews7%2Fmiddy-env","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisandrews7%2Fmiddy-env/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisandrews7%2Fmiddy-env/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisandrews7%2Fmiddy-env/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chrisandrews7","download_url":"https://codeload.github.com/chrisandrews7/middy-env/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248570561,"owners_count":21126467,"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-variables","middleware","middy","serverless"],"created_at":"2024-11-08T05:38:39.389Z","updated_at":"2025-04-14T16:21:07.950Z","avatar_url":"https://github.com/chrisandrews7.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Middy Env\n\nEnvironment variable middleware for the [middy](https://github.com/middyjs/middy) framework\n\n[![npm version](https://img.shields.io/npm/v/middy-env.svg?style=flat)](https://www.npmjs.com/package/middy-env)\n\n## Install\n\n```bash\nnpm install middy-env\n```\n\nThe specified environment variables will be parsed and passed into the handler. \n\n## Options\n\n- `cache` (boolean) (optional): Set it to `true` to skip further lookups of environment variables. Defaults to `false`.\n- `cacheExpiryInMillis` (int) (optional): Time in milliseconds for values to remain cached. Defaults to `undefined`.\n- `setToContext` (boolean) (optional): This will assign the parsed values to the `context` object\n  of the function handler rather than to `process.env`. Defaults to `true`.\n- `names` (object) (required): Map of environment variables to parse, where the key is the destination.  \nEither provide just the environment variable key. Or provide the key, type and fallback value e.g. `['KEY', 'string', 'fallbackValue']`.\n\nBy default parameters are assigned to the function handler's `context` object. They can instead be assigned to the Node.js `process.env` object by setting the `setToContext` flag to `false`.   \nIf no fallback value is provided a [ReferenceError](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError) will be thrown if an environment variable is undefined.\n\n## Supported Types\n- `string`\n- `int`\n- `float`\n- `bool`\n\n## Usage\n\n```js\nconst middy = require('middy');\nconst env = require('middy-env');\n\nconst handler = (event, context, callback) =\u003e {\n  callback(null, `Hello ${context.firstName} ${context.lastName}`);\n};\n\nmodule.exports = middy(handler)\n  .use(env({ \n    names: {\n      firstName: ['FIRST_NAME', 'string', 'World'],\n      lastName: 'LAST_NAME'\n    },\n    cache: true,\n    cacheExpiryInMillis: 3600000\n  }));\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisandrews7%2Fmiddy-env","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchrisandrews7%2Fmiddy-env","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisandrews7%2Fmiddy-env/lists"}