{"id":32122248,"url":"https://github.com/ymonb1291/dotenv-parser","last_synced_at":"2026-05-14T21:04:04.405Z","repository":{"id":62421810,"uuid":"319085041","full_name":"ymonb1291/dotenv-parser","owner":"ymonb1291","description":"A fast, zero-permission parser for '.env' files with support for multiline variables.","archived":false,"fork":false,"pushed_at":"2021-05-11T17:26:42.000Z","size":28,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-20T20:42:39.696Z","etag":null,"topics":["deno","dotenv","dotenv-parser","parser"],"latest_commit_sha":null,"homepage":"","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/ymonb1291.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-12-06T17:00:18.000Z","updated_at":"2021-05-11T17:26:45.000Z","dependencies_parsed_at":"2022-11-01T17:32:02.962Z","dependency_job_id":null,"html_url":"https://github.com/ymonb1291/dotenv-parser","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/ymonb1291/dotenv-parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ymonb1291%2Fdotenv-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ymonb1291%2Fdotenv-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ymonb1291%2Fdotenv-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ymonb1291%2Fdotenv-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ymonb1291","download_url":"https://codeload.github.com/ymonb1291/dotenv-parser/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ymonb1291%2Fdotenv-parser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33043249,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"online","status_checked_at":"2026-05-14T02:00:06.663Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["deno","dotenv","dotenv-parser","parser"],"created_at":"2025-10-20T20:34:04.682Z","updated_at":"2026-05-14T21:04:04.399Z","avatar_url":"https://github.com/ymonb1291.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dotenv-parser\n\n![GitHub Workflow Status](https://img.shields.io/github/workflow/status/ymonb1291/dotenv-parser/ci?label=ci)\n![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/ymonb1291/dotenv-parser?include_prereleases)\n![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/ymonb1291/dotenv-parser)\n[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/dotenv-parser/mod.ts)\n![GitHub](https://img.shields.io/github/license/ymonb1291/dotenv-parser)\n\n[![nest badge](https://nest.land/badge.svg)](https://nest.land/package/dotenv-parser)\n\nA fast, zero-permission parser for '.env' files with support for multiline\nvariables.\n\n# Usage\n\n## Import\n\nImport `dotenv-parser` from one of the following registries:\n\n```\n// From Deno.land\nimport { dotEnvParser } from \"https://deno.land/x/dotenv_parser@v1.0.2/mod.ts\";\n\n// From Nest.land\nimport { dotEnvParser } from \"https://x.nest.land/dotenv-parser@v1.0.2/mod.ts\";\n\n// From Denopkg\nimport { dotEnvParser } from \"https://denopkg.com/ymonb1291/dotenv-parser@v1.0.2/mod.ts\";\n\n// From Github\nimport { dotEnvParser } from \"https://raw.githubusercontent.com/ymonb1291/dotenv-parser/v1.0.2/mod.ts\";\n```\n\n## Read the `.env` file\n\n`dotenv-parser` doesn't ship with a way to read files. You must decode your\n`.env` file on your own.\n\nFor example:\n\n```\nconst decoder = new TextDecoder(\"utf-8\");\nconst raw = Deno.readFileSync(\".env\");\nconst data = decoder.decode(raw);\nconsole.log(dotEnvParser(data));\n```\n\nFor the purpose of this documentation, we'll simply declare a string variable\nthat contains the configuration.\n\nFor example:\n\n```\nconst config = `\n  SERVER_HOST=localhost\n  SERVER_PORT=3000\n  SERVER_HTTPS=true\n`;\n```\n\n## Parsing\n\nThe `dotEnvParser` function looks for `KEY=VALUE` pairs in a string and returns\nthem as an object where all keys and values are of type `string`:\n\n```\nconst res = dotEnvParser(config);\nconsole.log(res);\n//  Output:\n//    { SERVER_HOST: \"localhost\", SERVER_PORT: \"3000\", SERVER_HTTPS: \"true\" }\n```\n\n`DotEnvParser` can also try accept a second `boolean` parameter. When true, the\nparser will try to infer the type of the value. Numbers and booleans will then\nbe converted to their respective type:\n\n```\nconst res = dotEnvParser(config, true);\nconsole.log(res);\n//  Output:\n//    { SERVER_HOST: \"localhost\", SERVER_PORT: 3000, SERVER_HTTPS: true }\n```\n\n# dotEnvParser\n\nThe parser has the following signature\n\n```\nfunction dotEnvParser\u003cfalse\u003e(raw: string): Data;\nfunction dotEnvParser\u003cfalse\u003e(raw: string, infer: false): Data;\nfunction dotEnvParser\u003ctrue\u003e(raw: string, infer: true): TypedData;\n```\n\n## Data interface\n\n`Data` describes the object returned when the infer parameter is `false` or\n`undefined`. It describes a plain object where all values are of type `string`.\n\n```\ninterface Data {\n  [key: string]: string;\n}\n```\n\n## TypedData interface\n\n`TypedData` describes the object returned when the infer parameter is `true`. It\ndescribes a plain object where the values can be of type `string`, `number` or\n`boolean`.\n\n```\ninterface TypedData {\n  [key: string]: string | number | boolean;\n}\n```\n\n# Parsing rules\n\nThe parser supports key/value pairs formatted as `KEY=VALUE`. The following\nrules apply:\n\n- Empty lines are skipped\n- Lines beginning with `#` are treated as comments and are skipped\n- `KEY=VALUE` becomes `{KEY=\"VALUE\"}`\n  - Single quoted values can also be used: `KEY='VALUE'` also becomes\n    `{KEY=\"VALUE\"}`\n  - Double quoted values can also be used: `KEY=\"VALUE\"` also becomes\n    `{KEY=\"VALUE\"}`\n- Keys can contain upper case letters `A-Z`, lower case letters `a-z` and\n  underscore character `_`. Numbers `0-9` are also valid when not in first\n  position. For example:\n  - `_Key0=VALUE` is valid and becomes `{_Key0=\"VALUE\"}`\n  - `0Key_=VALUE` is not valid\n- Empty values are treated as empty string. `EMPTY=` becomes `{EMPTY=\"\"}`\n- Single and double quoted values keep their surrounding spaces. Non quoted\n  values do not.\n  - `KEY= VALUE` becomes `{KEY=\"VALUE\"}`\n  - `KEY=\" VALUE \"` becomes `{KEY=\" VALUE \"}`\n- Inner quotes are maintained. `JSON={\"KEY\": \"VALUE\"}` becomes\n  `{JSON=\"{\\\"KEY\\\": \\\"VALUE\\\"}\"}`\n- Multiline values are accepted with and without quotes. For example:\n  ```\n  SAY_HELLO=Hello\n  World!\n  ```\n  becomes `{SAY_HELLO: \"Hello\\nWorld!\"}`\n- Multiline values can contain `=` if escaped\n  ```\n  CALC=1+1\n  \\\\=2\n  ```\n  becomes `{CALC: \"1+1\\n=2\"}`\n- Multiline values can contain `#` if escaped\n  ```\n  HASH=Hello\n  \\\\#World\n  ```\n  becomes `{HASH: \"Hello\\n#World\"}`\n\n# Contributions\n\nPRs are welcome!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fymonb1291%2Fdotenv-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fymonb1291%2Fdotenv-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fymonb1291%2Fdotenv-parser/lists"}