{"id":28296927,"url":"https://github.com/kriasoft/envars","last_synced_at":"2025-06-15T05:32:03.429Z","repository":{"id":45494484,"uuid":"363116318","full_name":"kriasoft/envars","owner":"kriasoft","description":"Load environment variables securely from .env files, with seamless integration for Google Secret Manager to handle referenced secrets.","archived":false,"fork":false,"pushed_at":"2024-12-21T10:43:21.000Z","size":7046,"stargazers_count":11,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-12T10:23:32.860Z","etag":null,"topics":["aes-gcm","config","configuration","dotenv","env","environment","environment-variables","nodejs","passphrase","password","secret","secret-management","secrets","secrets-manager","settings","vite"],"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/kriasoft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"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,"zenodo":null},"funding":{"github":"koistya"}},"created_at":"2021-04-30T11:14:38.000Z","updated_at":"2025-01-13T14:17:19.000Z","dependencies_parsed_at":"2022-07-19T01:47:28.014Z","dependency_job_id":"c15240c1-db82-4187-b209-a2db5412a7e7","html_url":"https://github.com/kriasoft/envars","commit_stats":{"total_commits":9,"total_committers":2,"mean_commits":4.5,"dds":0.2222222222222222,"last_synced_commit":"4f005e9f9cb8a8ae5c817b1ab694a7e6a440ac58"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/kriasoft/envars","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kriasoft%2Fenvars","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kriasoft%2Fenvars/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kriasoft%2Fenvars/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kriasoft%2Fenvars/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kriasoft","download_url":"https://codeload.github.com/kriasoft/envars/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kriasoft%2Fenvars/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259926925,"owners_count":22933130,"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":["aes-gcm","config","configuration","dotenv","env","environment","environment-variables","nodejs","passphrase","password","secret","secret-management","secrets","secrets-manager","settings","vite"],"created_at":"2025-05-22T23:17:45.669Z","updated_at":"2025-06-15T05:32:03.416Z","avatar_url":"https://github.com/kriasoft.png","language":"JavaScript","funding_links":["https://github.com/sponsors/koistya","https://img.shields.io/badge/dynamic/json?color=%23ff424d\u0026label=Patreon\u0026style=flat-square\u0026query=data.attributes.patron_count\u0026suffix=%20patrons\u0026url=https%3A%2F%2Fwww.patreon.com%2Fapi%2Fcampaigns%2F233228","http://patreon.com/koistya"],"categories":[],"sub_categories":[],"readme":"# `envars` — environment variables loader\n\n[![NPM Version](https://img.shields.io/npm/v/envars?style=flat-square)](https://www.npmjs.com/package/envars)\n[![NPM Downloads](https://img.shields.io/npm/dm/envars?style=flat-square)](https://www.npmjs.com/package/envars)\n[![Donate](https://img.shields.io/badge/dynamic/json?color=%23ff424d\u0026label=Patreon\u0026style=flat-square\u0026query=data.attributes.patron_count\u0026suffix=%20patrons\u0026url=https%3A%2F%2Fwww.patreon.com%2Fapi%2Fcampaigns%2F233228)](http://patreon.com/koistya)\n[![Discord](https://img.shields.io/discord/643523529131950086?label=Chat\u0026style=flat-square)](https://discord.gg/bSsv7XM)\n\nLoads environment variables for the target environment from `.env` files using [dotenv](https://github.com/motdotla/dotenv); supports cloud secret providers such as [Google Secret Manager](https://cloud.google.com/secret-manager).\n\nBy default it attempts to load `.env` files from the current working directory using the following naming convention ([learn more](https://vitejs.dev/guide/env-and-mode.html#env-files)):\n\n```bash\n.env.\u003cenvironment\u003e.local     # Local overrides for \u003cenvironment\u003e\n.env.\u003cenvironment\u003e           # Environment-specific settings\n.env.local                   # Local overrides\n.env                         # Default settings\n```\n\nCreated and diligently upheld with the generous backing of these exceptional companies:\n\n\u003ca href=\"https://reactstarter.com/s/1\"\u003e\u003cimg src=\"https://reactstarter.com/s/1.png\" height=\"60\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://reactstarter.com/s/2\"\u003e\u003cimg src=\"https://reactstarter.com/s/2.png\" height=\"60\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://reactstarter.com/s/3\"\u003e\u003cimg src=\"https://reactstarter.com/s/3.png\" height=\"60\" /\u003e\u003c/a\u003e\n\n## How to Install\n\n```bash\n# with NPM\n$ npm install envars --save-dev\n\n# with Yarn\n$ yarn add envars --dev\n```\n\n## Usage\n\n```dotenv\n# .env\n# Environment variables for the local development environment\n# NOTE: Secret values need to follow this format:\n#       secret://[provider]/[resource]\nGOOGLE_CLOUD_PROJECT=example\nDB_PASSWORD=secret://google/projects/example/secrets/db-password/latest\n```\n\n```ts\n// core/env.ts\nimport { cleanEnv, str } from \"envalid\";\n\n/**\n * Sanitized and validated environment variables.\n * @see https://github.com/af/envalid#readme\n */\nexport default cleanEnv(process.env, {\n  GOOGLE_CLOUD_PROJECT: str(),\n  DB_PASSWORD: str(),\n});\n```\n\n```ts\nimport { loadEnv } from \"envars\";\n\nconst [env] = await loadEnv(\"production\", {\n  root: \".\",\n  schema: \"./core/env.ts\",\n  mergeTo: process.env,\n});\n```\n\n## API\n\n### loadEnv(mode?, options?)\n\n### mode\n\nType: `string` (optional)\u003cbr\u003e\nDefault: `undefined`\u003cbr\u003e\nExample: `production`, `development`, `staging`, etc.\n\n### options\n\nType: `object` (optional)\n\n#### root\n\nType: `string` (optional)\u003cbr\u003e\nDefault: `.` (current working directory).\n\nThe root directory where it looks for `.env` files.\n\n#### schema\n\nType: `string` (optional)\u003cbr\u003e\nDefault: `undefined`\u003cbr\u003e\nExample: `./core/env.ts`\n\nThe path to the TypeScript or JavaScript module exporting a sanitized environment object. Example:\n\n```ts\nimport { cleanEnv, str } from \"envalid\";\n\nexport default cleanEnv(process.env, {\n  GOOGLE_CLOUD_PROJECT: str(),\n  DB_PASSWORD: str(),\n});\n```\n\nOr, another example using Zod:\n\n```ts\nimport { z } from \"zod\";\n\nexport const env = z\n  .object({\n    GOOGLE_CLOUD_PROJECT: z.string(),\n    DB_PASSWORD: z.string(),\n  })\n  .parse(process.env);\n```\n\n#### files\n\nType: `string[]` (optional)\u003cbr\u003e\nDefault: `[\n  \".env.\u003cenvironment\u003e.local\",\n  \".env.\u003cenvironment\u003e\",\n  \".env.local\",\n  \".env\"\n]`\n\nThe list of file patterns where to look for `.env` files.\n\n#### mergeTo\n\nType: `object` (optional)\u003cbr\u003e\nDefault: `undefined`\nExample: `process.env`\n\nThe object where to merge the loaded environment variables.\n\n## Usage with Vite\n\n```ts\nimport { defineConfig } from \"vite\";\nimport { loadEnv } from \"envars\";\n\nexport default defineConfig(async ({ mode }) =\u003e {\n  const [env] = await loadEnv(mode, {\n    root: \"../\",\n    schema: \"./core/env.ts\",\n    mergeTo: process.env,\n  });\n\n  return {\n    build: {\n      ssr: \"index.ts\",\n      target: \"esnext\",\n      sourcemap: true,\n    },\n  };\n});\n```\n\n### References\n\n- https://cloud.google.com/secret-manager/docs\n\n## Backers 💰\n\n\u003ca href=\"https://reactstarter.com/b/1\"\u003e\u003cimg src=\"https://reactstarter.com/b/1.png\" height=\"60\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://reactstarter.com/b/2\"\u003e\u003cimg src=\"https://reactstarter.com/b/2.png\" height=\"60\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://reactstarter.com/b/3\"\u003e\u003cimg src=\"https://reactstarter.com/b/3.png\" height=\"60\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://reactstarter.com/b/4\"\u003e\u003cimg src=\"https://reactstarter.com/b/4.png\" height=\"60\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://reactstarter.com/b/5\"\u003e\u003cimg src=\"https://reactstarter.com/b/5.png\" height=\"60\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://reactstarter.com/b/6\"\u003e\u003cimg src=\"https://reactstarter.com/b/6.png\" height=\"60\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://reactstarter.com/b/7\"\u003e\u003cimg src=\"https://reactstarter.com/b/7.png\" height=\"60\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://reactstarter.com/b/8\"\u003e\u003cimg src=\"https://reactstarter.com/b/8.png\" height=\"60\" /\u003e\u003c/a\u003e\n\n## Related Projects\n\n- [React Starter Kit](https://github.com/kriasoft/react-starter-kit) — front-end boilerplate (TypeScript, React, Material UI, Vite)\n- [Full-stack Starter Kit](https://github.com/kriasoft/relay-starter-kit) — monorepo boilerplate (TypeScript, Vite, GraphQL.js, React, and Relay)\n\n## How to Contribute\n\nPlease [fork the repo](https://github.com/kriasoft/envars/fork), create a [PR](https://docs.github.com/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request), or send me a message on [Discord](https://discord.gg/bSsv7XM) (`@koistya`).\n\n```bash\n$ git clone https://github.com/\u003cusername\u003e/envars.git\n$ cd ./envars\n$ corepack enable\n$ yarn test\n```\n\n## License\n\nCopyright © 2021-present Kriasoft. This source code is licensed under the MIT license found in the\n[LICENSE](https://github.com/kriasoft/envars/blob/main/LICENSE) file.\n\n---\n\n\u003csup\u003eMade with ♥ by Konstantin Tarkus ([@koistya](https://twitter.com/koistya), [blog](https://medium.com/@koistya))\nand [contributors](https://github.com/kriasoft/envars/graphs/contributors).\u003c/sup\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkriasoft%2Fenvars","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkriasoft%2Fenvars","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkriasoft%2Fenvars/lists"}