{"id":15655313,"url":"https://github.com/simenandre/nestjs-envalid","last_synced_at":"2025-09-20T10:31:57.972Z","repository":{"id":40271704,"uuid":"386600946","full_name":"simenandre/nestjs-envalid","owner":"simenandre","description":"Simple wrapper on top of envalid for NestJS","archived":false,"fork":false,"pushed_at":"2024-12-09T04:34:41.000Z","size":465,"stargazers_count":27,"open_issues_count":14,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-07T07:44:00.480Z","etag":null,"topics":["12factor","environment","javascript","nestjs","node","nodejs","validation"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simenandre.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2021-07-16T10:39:41.000Z","updated_at":"2024-12-15T21:39:55.000Z","dependencies_parsed_at":"2023-10-27T19:37:41.797Z","dependency_job_id":"45dd506b-bf5a-44d3-9a1a-e4361fde29c6","html_url":"https://github.com/simenandre/nestjs-envalid","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simenandre%2Fnestjs-envalid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simenandre%2Fnestjs-envalid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simenandre%2Fnestjs-envalid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simenandre%2Fnestjs-envalid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simenandre","download_url":"https://codeload.github.com/simenandre/nestjs-envalid/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233653526,"owners_count":18709130,"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":["12factor","environment","javascript","nestjs","node","nodejs","validation"],"created_at":"2024-10-03T12:57:57.176Z","updated_at":"2025-09-20T10:31:57.622Z","avatar_url":"https://github.com/simenandre.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003enestjs-envalid\u003c/h1\u003e\n\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=flat-square)](http://commitizen.github.io/cz-cli/)\n\n\u003e [Envalid][] is a small library for validating and accessing environment\n\u003e variables in Node.js (v14.16 or later) programs, aiming to:\n\u003e\n\u003e - ensure that your program only runs when all of its environment dependencies\n\u003e   are met\n\u003e - give you executable documentation about the environment your program expects\n\u003e   to run in\n\u003e - give you an immutable API for your environment variables, so they don't\n\u003e   change from under you while the program is running\n\n---\n\n`nestjs-envalid` is simple wrapper on top of [envalid][] made for [NestJS][]\n\n[envalid]: https://github.com/af/envalid\n[nestjs]: https://github.com/nestjs/nest\n\n**Note**: This package is [pure ESM][esm], which requires you to add `\"type\": \"module\"` to\nyour `package.json` file. If you're using CommonJS, you can for now [use the `legacy`\ntag on NPM to use the latest version of v1][v1]. The legacy version will be supported\nfor now, but we will eventually drop support for it.\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n[v1]: #common-js--version-1\n\n## Quickstart\n\n```sh\nyarn add nestjs-envalid envalid\n```\n\nTo improve readability you can configure the variables in a separate file named\n`config.ts`, like the example below:\n\n```typescript\nimport { makeValidators, num, Static } from 'nestjs-envalid';\n\nexport const validators = makeValidators({\n  PORT: num({ default: 3000 }),\n});\n\nexport type Config = Static\u003ctypeof validators\u003e;\n```\n\nThe `validators` can then be added to `EnvalidModule`, like so:\n\n```typescript\nimport { EnvalidModule } from 'nestjs-envalid';\nimport { validators } from './config';\n\n@Module({\n  imports: [EnvalidModule.forRoot({ validators })],\n})\nexport class AppModule {}\n```\n\nTo inject your configuration, you can do this:\n\n```typescript\nimport { ENVALID, Config } from './config';\n\n@Injectable()\nexport class SomeService {\n  constructor(@Inject(ENVALID) private readonly env: Config) {}\n\n  someMethod() {\n    if (this.env.isProd) {\n      const other = this.env.HELLO_WORLD;\n    }\n  }\n}\n```\n\n## Add support for dotenv\n\nYou'll need to install `dotenv`. \n\n```sh\nyarn add dotenv\n```\n\nNext, just set `useDotenv` to `true`\n\n```typescript\nimport { validators } from './config';\n@Module({\n  imports: [EnvalidModule.forRoot({ validators, useDotenv: true })],\n})\nexport class AppModule {}\n```\n\n## v3 / Next\n\nThere's an upcoming v3 release which uses `envalid` v8, you can try it out by using the\n`next` tag:\n\n```shell\nyarn add nestjs-envalid@next envalid\n```\n\n[Read more here in #53](https://github.com/simenandre/nestjs-envalid/issues/53)\n\n## Common JS / Version 1\n\nIf you need either support for Node 8.12 or above or CommonJS, you can use the\nlegacy version of this package. To do so, you'll need to use the `legacy` tag.\n\n```shell\nyarn add nestjs-envalid@legacy envalid\n```\n\nThe legacy version will be supported for now, but we will eventually drop support for it.\nWe will notify you when we eventually do, at least a few months before, but you should\nmigrate to ESM as soon as possible.\n\n## Contributing\n\nContributions, issues and feature requests are welcome!\u003cbr /\u003eFeel free to check\n[issues page](https://github.com/cobraz/nestjs-envalid/issues).\n\nGive a ⭐️ if this project helped you!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimenandre%2Fnestjs-envalid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimenandre%2Fnestjs-envalid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimenandre%2Fnestjs-envalid/lists"}