{"id":18336316,"url":"https://github.com/launchpadlab/expose-env-middleware","last_synced_at":"2025-04-09T19:55:21.377Z","repository":{"id":57149060,"uuid":"183113426","full_name":"LaunchPadLab/expose-env-middleware","owner":"LaunchPadLab","description":"Expose env variables to client-side code via express","archived":false,"fork":false,"pushed_at":"2020-03-14T13:15:12.000Z","size":177,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-09T19:55:13.042Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/LaunchPadLab.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}},"created_at":"2019-04-24T00:01:18.000Z","updated_at":"2019-06-11T16:52:41.000Z","dependencies_parsed_at":"2022-09-05T13:40:20.339Z","dependency_job_id":null,"html_url":"https://github.com/LaunchPadLab/expose-env-middleware","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/LaunchPadLab%2Fexpose-env-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LaunchPadLab%2Fexpose-env-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LaunchPadLab%2Fexpose-env-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LaunchPadLab%2Fexpose-env-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LaunchPadLab","download_url":"https://codeload.github.com/LaunchPadLab/expose-env-middleware/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103911,"owners_count":21048245,"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":[],"created_at":"2024-11-05T20:07:28.161Z","updated_at":"2025-04-09T19:55:21.334Z","avatar_url":"https://github.com/LaunchPadLab.png","language":"JavaScript","readme":"# expose-env-middleware\n\nExpress middleware to dynamically expose environment variables to client-side code via `window.process.env`:\n\n```js\n// server.js\n\nconst app = require('express')()\nconst exposeEnvMiddleware = require('expose-env-middleware')\n\n// Pass it a function that returns env vars\nconst getEnv = () =\u003e ({ FOO: 'bar' })\napp.get('/env', exposeEnvMiddleware(getEnv))\napp.listen(...)\n```\n```html\n\u003c!-- index.html --\u003e\n\n\u003cscript src=\"/env\"\u003e\u003c/script\u003e\n\u003cscript\u003e console.log(process.env.FOO) // -\u003e 'bar' \u003c/script\u003e\n```\n\nThis setup allows env vars to reload each time index.html is fetched.\n\n## API\n\n* `middleware(getEnv[, options])`\n  * `getEnv`: A function that returns an object of env variables.\n  * `options.template` (optional, default=`defaultTemplate`) Template function for serializing the env object into a file. Default is shown below:\n\n\n  ```js\n  function defaultTemplate (env) {\n    return `\n      window.process = {\n        env: ${ JSON.stringify(env) }\n      }  \n    `\n  }\n  ```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaunchpadlab%2Fexpose-env-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flaunchpadlab%2Fexpose-env-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaunchpadlab%2Fexpose-env-middleware/lists"}