{"id":16726509,"url":"https://github.com/shahriar-shojib/atenv","last_synced_at":"2025-06-26T16:09:32.673Z","repository":{"id":40659544,"uuid":"420379541","full_name":"shahriar-shojib/atenv","owner":"shahriar-shojib","description":"modern dotenv replacement","archived":false,"fork":false,"pushed_at":"2022-04-30T00:27:04.000Z","size":173,"stargazers_count":15,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-26T16:07:27.177Z","etag":null,"topics":["decorators","dotenv","env","parser","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/shahriar-shojib.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":"2021-10-23T10:20:55.000Z","updated_at":"2024-09-14T15:32:26.000Z","dependencies_parsed_at":"2022-08-10T00:10:39.403Z","dependency_job_id":null,"html_url":"https://github.com/shahriar-shojib/atenv","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/shahriar-shojib/atenv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahriar-shojib%2Fatenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahriar-shojib%2Fatenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahriar-shojib%2Fatenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahriar-shojib%2Fatenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shahriar-shojib","download_url":"https://codeload.github.com/shahriar-shojib/atenv/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahriar-shojib%2Fatenv/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262099716,"owners_count":23258668,"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":["decorators","dotenv","env","parser","typescript"],"created_at":"2024-10-12T22:53:23.952Z","updated_at":"2025-06-26T16:09:32.278Z","avatar_url":"https://github.com/shahriar-shojib.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## AtEnv is a modern replacement for parsing env on Typescript projects\r\n\r\n[![Run Tests](https://github.com/shahriar-shojib/atenv/actions/workflows/tests.yml/badge.svg)](https://github.com/shahriar-shojib/atenv/actions/workflows/tests.yml)\r\n[![Publish to NPM](https://github.com/shahriar-shojib/atenv/actions/workflows/publish-to-npm.yml/badge.svg)](https://github.com/shahriar-shojib/atenv/actions/workflows/publish-to-npm.yml)\r\n\r\n### How to install\r\n\r\n```bash\r\nnpm install atenv\r\n```\r\n\r\n## How to use\r\n\r\nDeclare a class which you want to parse env to\r\n\r\n```typescript\r\nimport 'reflect-metadata'; // required\r\nimport { IsEnum }  from 'class-validator';\r\n\r\n\r\nexport enum NodeEnv = {\r\n\tDEV = 'development',\r\n\tPRODUCTION = 'production'\r\n}\r\n\r\nclass AWS {\r\n\t@Env('AWS_SECRET')\r\n\tsecret: string;\r\n\r\n\t@Env('AWS_KEY')\r\n\tkey: string;\r\n}\r\n\r\nexport class AppConfig {\r\n\t@Env('PORT')\r\n\t@IsDefined() //you can use class validator decorators here\r\n\tport: number; // gets transformed to number automatically\r\n\r\n\t// it is also possible to define child classes for ease of use\r\n\t@Section(() =\u003e AWS)\r\n\taws: AWS;\r\n\r\n\t@Env('NODE_ENV')\r\n\t@IsEnum(NodeEnv); // throws error if not defined\r\n\tnodeEnv: NodeEnv;\r\n\r\n\r\n\t//helper getters are okay too\r\n\tget isDev() {\r\n\t\treturn this.nodeEnv === NodeEnv.DEV;\r\n\t}\r\n}\r\n\r\nexport const appConfig = parseEnv(AppConfig); //appConfig is now an instance of AppConfig containing values from .env\r\n\r\n//now access your env like this\r\n\r\nappConfig.port // number\r\n```\r\n\r\n\u003e Booleans, and Numbers are automatically transformed, if you need to use custom transformation logic, you can use the `@Transform` Decorator from [class-transformer](https://github.com/typestack/class-transformer#additional-data-transformation)\r\n\r\n## Default and optional values\r\n\r\nit is possible to set default values like this\r\n\r\n```typescript\r\nexport enum NodeEnv = {\r\n\tDEV = 'development',\r\n\tPRODUCTION = 'production'\r\n}\r\n\r\nexport class AppConfig {\r\n\t@Env('NODE_ENV')\r\n\t@IsEnum(NodeEnv); // throws error if not defined\r\n\t@IsOptional() // class validator will treat this value as optional\r\n\tnodeEnv: NodeEnv = NodeEnv.DEV;\r\n}\r\n\r\nconst myEnv = parseEnv(AppConfig)\r\n\r\nmyEnv.nodeEnv === 'development' //true\r\n```\r\n\r\n## Custom Env files\r\n\r\n```typescript\r\nexport enum NodeEnv = {\r\n\tDEV = 'development',\r\n\tPRODUCTION = 'production'\r\n}\r\n\r\nexport class AppConfig {\r\n\t@Env('NODE_ENV')\r\n\t@IsEnum(NodeEnv); // throws error if not defined\r\n\t@IsOptional() // class validator will treat this value as optional\r\n\tnodeEnv: NodeEnv = NodeEnv.DEV;\r\n}\r\n\r\nconst myEnv = parseEnv(AppConfig, {\r\n\tdotEnvOptions: {\r\n\t\tpath: '.env.development' // or a path to your env\r\n\t}\r\n})\r\n```\r\n\r\n## Additional Options\r\n\r\nYou can parse additional options for class-validator and class-transformer\r\n\r\n```typescript\r\nparseEnv(YourClass, {\r\n\ttransformOptions: {} // override classToclass options\r\n\tvalidatorOptions: {} // override validateSync options\r\n});\r\n```\r\n\r\nDocs for options:\r\n\r\n- [transformOptions](https://github.com/typestack/class-transformer/blob/develop/src/interfaces/class-transformer-options.interface.ts)\r\n- [validatorOptions](https://github.com/typestack/class-validator#passing-options)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshahriar-shojib%2Fatenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshahriar-shojib%2Fatenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshahriar-shojib%2Fatenv/lists"}