{"id":23633188,"url":"https://github.com/tuki0918/dotenv-zod-validator","last_synced_at":"2025-06-24T23:04:34.307Z","repository":{"id":268795561,"uuid":"905290717","full_name":"tuki0918/dotenv-zod-validator","owner":"tuki0918","description":"A very lightweight library for validating and transforming environment variables using Zod.","archived":false,"fork":false,"pushed_at":"2025-06-12T10:53:53.000Z","size":327,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-23T01:07:33.605Z","etag":null,"topics":["dotenv","nextjs","nodejs","react","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/dotenv-zod-validator","language":"TypeScript","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/tuki0918.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-12-18T14:30:18.000Z","updated_at":"2025-06-12T10:53:57.000Z","dependencies_parsed_at":"2024-12-19T01:22:06.508Z","dependency_job_id":"e3b8d7bd-bd05-4537-8a80-4d57ab70bd31","html_url":"https://github.com/tuki0918/dotenv-zod-validator","commit_stats":null,"previous_names":["tuki0918/dotenv-zod-validator"],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/tuki0918/dotenv-zod-validator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuki0918%2Fdotenv-zod-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuki0918%2Fdotenv-zod-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuki0918%2Fdotenv-zod-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuki0918%2Fdotenv-zod-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tuki0918","download_url":"https://codeload.github.com/tuki0918/dotenv-zod-validator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuki0918%2Fdotenv-zod-validator/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261771064,"owners_count":23207212,"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":["dotenv","nextjs","nodejs","react","typescript"],"created_at":"2024-12-28T04:49:14.526Z","updated_at":"2025-06-24T23:04:34.296Z","avatar_url":"https://github.com/tuki0918.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dotenv-zod-validator\n\n\u003cp\u003e\n\u003ca href=\"https://www.npmjs.com/package/dotenv-zod-validator\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/dotenv-zod-validator\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n`dotenv-zod-validator` is a very lightweight library for validating and transforming environment variables using Zod.\n\n## Installation\n\n```bash\nnpm install dotenv-zod-validator\n```\n\n## Usage (Node)\n\n.env\n\n```bash\nNODE_ENV=\"development\"\nPORT=\"3000\"\nBOOLEAN_FLAG=\"true\"\n__OTHER__=\"__other__\"\n```\n\ncode\n\n```typescript\nimport { zenv } from \"dotenv-zod-validator\";\n\nconst schema = zenv.object({\n    NODE_ENV: zenv.enum([\"development\", \"production\", \"test\"]),\n    PORT: zenv.number(),\n    BOOLEAN_FLAG: zenv.boolean(),\n    OPTIONAL_VAR: zenv.string().optional(),\n});\n\nconst ENV = zenv.validate(schema);\n// NODE_ENV: \"development\" (string)\n// PORT: 3000 (number)\n// BOOLEAN_FLAG: true (boolean)\n// OPTIONAL_VAR: undefined\n\n// Cannot assign to 'NODE_ENV' because it is a read-only property.\n// ENV.NODE_ENV = \"production\"\n```\n\n## Usage (Next.js)\n\n.env\n\n```bash\nNEXT_PUBLIC_MY_VALUE=\"abc\"\nMY_SECRET=\"xyz\"\n```\n\nutils/dotenv.public.ts\n\n```typescript\nimport { zenv } from \"dotenv-zod-validator\";\n\nexport const schema = zenv.object({\n    NEXT_PUBLIC_MY_VALUE: zenv.string(),\n});\n\nexport const ENV = zenv.validate(schema, {\n    NEXT_PUBLIC_MY_VALUE: process.env.NEXT_PUBLIC_MY_VALUE,\n});\n// NEXT_PUBLIC_MY_VALUE: \"abc\"\n```\n\nutils/dotenv.ts\n\n```typescript\nimport { zenv } from \"dotenv-zod-validator\";\nimport { schema as publicSchema } from \"@/utils/dotenv.public\";\n\nconst schema = zenv.object({\n    MY_SECRET: zenv.string(),\n});\n\nexport const ENV = zenv.validate(publicSchema.merge(schema));\n// NEXT_PUBLIC_MY_VALUE: \"abc\"\n// MY_SECRET: \"xyz\"\n```\n\n(optional) [instrumentation.ts](https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation)\n\n\nYou can enforce environment variable checks when starting the Next.js server.\n\n```\nimport \"@/utils/dotenv\";\n```\n\n## Custom Helpers\n\n| Method | Description | undefined | empty | and error |\n| ---- | ---- | ---- | ---- | ---- |\n| object | Alias for `z.object` | _ | _ | _ |\n| enum | Alias for `z.enum` | ❌️ | ❌️ | `invalid text` |\n| string | Alias for `z.string` | ❌️ | ✅️ | _ |\n| number | Converts to a number. | ❌️ | ❌️ | `invalid number` |\n| boolean | Converts to a boolean. (TRUE: `true`, `TRUE`, `1` / FALSE: `other`) | ❌️ | ❌️ | _ |\n\n## Tests\n\n```\nnpm run test\n```\n\n\n## License\n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftuki0918%2Fdotenv-zod-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftuki0918%2Fdotenv-zod-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftuki0918%2Fdotenv-zod-validator/lists"}