{"_id":"@boostpack/nestjs-config","_rev":"3-b2209bdd9cd536495be07a8cce97e2f4","name":"@boostpack/nestjs-config","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"@boostpack/nestjs-config","version":"1.0.0","keywords":["boostpack","config","configuration","nestjs","nest","joi","typescript","type-safe","type-safety","validation","environment","env","process-env","schema","runtime-validation","config-validation","mock","testing","type-inference"],"license":"MIT","_id":"@boostpack/nestjs-config@1.0.0","maintainers":[{"name":"timur2915","email":"timur2915@gmail.com"}],"contributors":[{"name":"Timur Popov","email":"timur2915@gmail.com"}],"homepage":"https://github.com/boostpack/boostpack#readme","bugs":{"url":"https://github.com/boostpack/boostpack/issues"},"nx":{"tags":["scope:nestjs"]},"dist":{"shasum":"5298854b2c5917257c9336a4b7bd8e8a2c3fabfa","tarball":"https://registry.npmjs.org/@boostpack/nestjs-config/-/nestjs-config-1.0.0.tgz","fileCount":9,"integrity":"sha512-G256mT+P1wGnxkfv9A5K+nm7442sxH2/J7RcL4xVMZ/OfogeZPcXTCUCeJU/c7tJcL/YARVyzZS6LTAMBUgG7g==","signatures":[{"sig":"MEUCIAfLp/RoA5m2ri88AZfmkjw8VPgrz/LTv7cUk2/nlO0MAiEAus140KXosmwP4TGIU8HoVfZuAbNQwDpPxFsVaiFy6Fk=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":12166},"main":"./dist/index.cjs.js","types":"./dist/index.esm.d.ts","module":"./dist/index.esm.js","exports":{".":{"types":"./dist/index.esm.d.ts","import":"./dist/index.esm.js","default":"./dist/index.esm.js","require":"./dist/index.cjs.js","@boostpack/source":"./src/index.ts"},"./package.json":"./package.json"},"gitHead":"a830acc71f58a1d661d6b231f3ef6c7596b55937","_npmUser":{"name":"timur2915","email":"timur2915@gmail.com"},"repository":{"url":"git+https://github.com/boostpack/boostpack.git","type":"git","directory":"packages/nestjs/config"},"_npmVersion":"11.6.2","description":"Type-safe runtime configuration with Joi validation and schema-driven type inference","directories":{},"_nodeVersion":"24.13.0","dependencies":{"@boostpack/joi-extract-type":"^1.0.0"},"_hasShrinkwrap":false,"peerDependencies":{"joi":">=17.0.0"},"_npmOperationalInternal":{"tmp":"tmp/nestjs-config_1.0.0_1771625882080_0.9164467750455279","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@boostpack/nestjs-config","version":"1.0.1","keywords":["boostpack","config","configuration","nestjs","nest","joi","typescript","type-safe","type-safety","validation","environment","env","process-env","schema","runtime-validation","config-validation","mock","testing","type-inference"],"license":"MIT","_id":"@boostpack/nestjs-config@1.0.1","maintainers":[{"name":"timur2915","email":"timur2915@gmail.com"}],"contributors":[{"name":"Timur Popov","email":"timur2915@gmail.com"}],"homepage":"https://github.com/boostpack/boostpack#readme","bugs":{"url":"https://github.com/boostpack/boostpack/issues"},"nx":{"tags":["scope:nestjs"]},"dist":{"shasum":"8a5a11cb32f8b3ae442cc307d347e55c3c24288e","tarball":"https://registry.npmjs.org/@boostpack/nestjs-config/-/nestjs-config-1.0.1.tgz","fileCount":9,"integrity":"sha512-ni9VOL9e6JztsBVESfUOJKmkUSqtZb55CLHl5JoZSNgUMjH7SgC9ejIianEi2HjuR/mExvZLTmuR+FQKcYIrmg==","signatures":[{"sig":"MEQCIGMaEYgK5F4zGYvcB3Mw6lI+5WmL4mIBYu57pNbaH9N6AiAoqdkecYBNt6SdWmsRAR/EZip25LsfOL/gW+VEotpXEQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":12158},"main":"./dist/index.cjs.js","types":"./dist/index.d.ts","module":"./dist/index.esm.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.esm.js","default":"./dist/index.esm.js","require":"./dist/index.cjs.js","@boostpack/source":"./src/index.ts"},"./package.json":"./package.json"},"gitHead":"6f4103b16e89152312fa1f989c0141ecee863cb1","_npmUser":{"name":"timur2915","email":"timur2915@gmail.com"},"repository":{"url":"git+https://github.com/boostpack/boostpack.git","type":"git","directory":"packages/nestjs/config"},"_npmVersion":"11.6.2","description":"Type-safe runtime configuration with Joi validation and schema-driven type inference","directories":{},"_nodeVersion":"24.13.0","dependencies":{"@boostpack/joi-extract-type":"^1.0.0"},"_hasShrinkwrap":false,"peerDependencies":{"joi":">=17.0.0"},"_npmOperationalInternal":{"tmp":"tmp/nestjs-config_1.0.1_1772004693302_0.7638630162644908","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@boostpack/nestjs-config","version":"1.0.2","description":"Type-safe runtime configuration with Joi validation and schema-driven type inference","license":"MIT","contributors":[{"name":"Timur Popov","email":"timur2915@gmail.com"}],"repository":{"type":"git","url":"git+https://github.com/boostpack/boostpack.git","directory":"packages/nestjs/config"},"main":"./dist/index.cjs.js","module":"./dist/index.esm.js","types":"./dist/index.d.ts","exports":{"./package.json":"./package.json",".":{"@boostpack/source":"./src/index.ts","types":"./dist/index.d.ts","import":"./dist/index.esm.js","require":"./dist/index.cjs.js","default":"./dist/index.esm.js"}},"keywords":["boostpack","config","configuration","nestjs","nest","joi","typescript","type-safe","type-safety","validation","environment","env","process-env","schema","runtime-validation","config-validation","mock","testing","type-inference"],"nx":{"tags":["scope:nestjs"]},"peerDependencies":{"joi":">=17.0.0"},"dependencies":{"@boostpack/joi-extract-type":"^1.0.1"},"gitHead":"f6ebcae9ecb3058151e86c0184fa5c333a934460","_id":"@boostpack/nestjs-config@1.0.2","bugs":{"url":"https://github.com/boostpack/boostpack/issues"},"homepage":"https://github.com/boostpack/boostpack#readme","_nodeVersion":"24.13.0","_npmVersion":"11.6.2","dist":{"integrity":"sha512-9k+Hh0f6WFn9MLblkl/L1EL1W9MLLuKDywQiaLFRaco0RL3Jh22gybKFcLxQAAXky+wRzKXLxV90b224Dm7VAA==","shasum":"3ba92d3d4c1ab071147e76ccbd4df9e09d349254","tarball":"https://registry.npmjs.org/@boostpack/nestjs-config/-/nestjs-config-1.0.2.tgz","fileCount":9,"unpackedSize":12158,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCMFjoJuTgLUWETOVPu68m0ErcM5yEmko5Q0Yly3GmQ3wIgWLD85fl211K++Y6OK9JhbD0OBcLpdd4AHpa9Yp2LHkE="}]},"_npmUser":{"name":"timur2915","email":"timur2915@gmail.com"},"directories":{},"maintainers":[{"name":"timur2915","email":"timur2915@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/nestjs-config_1.0.2_1772195161805_0.004270716941523034"},"_hasShrinkwrap":false}},"time":{"created":"2026-02-20T22:18:01.986Z","modified":"2026-02-27T12:26:02.123Z","1.0.0":"2026-02-20T22:18:02.228Z","1.0.1":"2026-02-25T07:31:33.473Z","1.0.2":"2026-02-27T12:26:01.975Z"},"bugs":{"url":"https://github.com/boostpack/boostpack/issues"},"license":"MIT","homepage":"https://github.com/boostpack/boostpack#readme","keywords":["boostpack","config","configuration","nestjs","nest","joi","typescript","type-safe","type-safety","validation","environment","env","process-env","schema","runtime-validation","config-validation","mock","testing","type-inference"],"repository":{"type":"git","url":"git+https://github.com/boostpack/boostpack.git","directory":"packages/nestjs/config"},"description":"Type-safe runtime configuration with Joi validation and schema-driven type inference","contributors":[{"name":"Timur Popov","email":"timur2915@gmail.com"}],"maintainers":[{"name":"timur2915","email":"timur2915@gmail.com"}],"readme":"# @boostpack/nestjs-config\n\nType-safe environment configuration with Joi validation for NestJS.\n\n## Problem\n\n`@nestjs/config` has four pain points:\n\n1. **Validation on import** — config is validated at import time, which breaks tests and complicates lazy loading.\n2. **No type safety** — `configService.get('KEY')` returns `unknown`, forcing you to duplicate schema types manually.\n3. **Testing is painful** — mocking `ConfigService` is verbose, and there's no way to see which env vars your code actually needs.\n4. **Boilerplate** — requires module registration (`ConfigModule.forRoot()`), injection, and `ConfigService` — all for a simple key-value lookup.\n\nThis package solves all: validation happens when you call `createConfig()`, types are inferred directly from the Joi schema, and the built-in mock system shows exactly which keys are accessed — unmocked keys throw a descriptive error, making it easy to catch missing env vars in tests.\n\nWhile originally designed as a `@nestjs/config` replacement, the package has no NestJS dependency and works in any Node.js project.\n\n## Comparison\n\n### Before — `@nestjs/config`\n\n```typescript\n// app.module.ts — register the module\n@Module({\n  imports: [ConfigModule.forRoot({ isGlobal: true })],\n})\nexport class AppModule {}\n\n// database-config.service.ts — typed wrapper over ConfigService\n@Injectable()\nexport class DatabaseConfigService {\n  constructor(private readonly configService: ConfigService) {}\n\n  get host(): string {\n    return this.configService.get<string>('DB_HOST');          // string | undefined, no guarantee\n  }\n\n  get port(): number {\n    return +(this.configService.get<string>('DB_PORT'));        // manual number conversion\n  }\n\n  get ssl(): boolean {\n    return this.configService.get('DB_SSL') === 'true';        // manual boolean conversion\n  }\n}\n\n// database-config.module.ts — register the wrapper\n@Module({\n  providers: [DatabaseConfigService],\n  exports: [DatabaseConfigService],\n})\nexport class DatabaseConfigModule {}\n```\n\n### After — `@boostpack/nestjs-config`\n\n```typescript\n// database-config.service.ts — schema + accessors in one place\n@Injectable()\nexport class DatabaseConfigService {\n  private readonly config = createConfig(\n    Joi.object({\n      DB_HOST: Joi.string().required(),\n      DB_PORT: Joi.number().required(),\n      DB_SSL: Joi.boolean().default(false),\n    }),\n  );\n\n  get host(): string {\n    return this.config.get('DB_HOST'); // string — guaranteed, validated\n  }\n\n  get port(): number {\n    return this.config.get('DB_PORT'); // number — already converted by Joi\n  }\n\n  get ssl(): boolean {\n    return this.config.get('DB_SSL');  // boolean — already converted by Joi\n  }\n}\n```\n\nNo `ConfigModule.forRoot()`, no `ConfigService` injection, no manual type casting. Types are inferred from the Joi schema — no duplication needed.\n\n## Installation\n\n```bash\nnpm install @boostpack/nestjs-config joi\n```\n\n## Usage\n\n```typescript\nimport Joi from 'joi';\nimport { createConfig } from '@boostpack/nestjs-config';\n\nconst appConfig = createConfig(\n  Joi.object({\n    HOST: Joi.string().default('localhost'),\n    PORT: Joi.number().required(),\n    DEBUG: Joi.boolean().default(false),\n  }),\n);\n\nappConfig.get('HOST');  // string\nappConfig.get('PORT');  // number\nappConfig.get('DEBUG'); // boolean\nappConfig.getAll();     // { HOST: string; PORT: number; DEBUG: boolean }\n```\n\nKeys are validated at compile time — `appConfig.get('TYPO')` is a type error.\n\n### Required, optional, default\n\n```typescript\nJoi.string().required()    // string — must be in env\nJoi.number()               // number | undefined — can be missing\nJoi.string().default('x')  // string — Joi fills the default if missing\n```\n\n`.default()` makes the field always present — if the env var is missing, Joi substitutes the default value. The type reflects this: `string`, not `string | undefined`. Note that `.required().default()` still requires the env var to be set — the default is ignored.\n\n### Testing with mocks\n\nMocks bypass validation entirely — no real env vars needed:\n\n```typescript\nimport { setMockEnvValue, clearMockEnvValues } from '@boostpack/nestjs-config';\n\nbeforeEach(() => {\n  setMockEnvValue('DATABASE_URL', 'mock://localhost');\n});\n\nafterEach(() => {\n  clearMockEnvValues();\n});\n```\n\nWhen mocks are active, `createConfig()` skips Joi validation and returns mocked values. Accessing an unmocked key throws with a descriptive error.\n\n## API\n\n### `createConfig(schema, env?)`\n\nCreates a type-safe config from a Joi object schema.\n\n- `schema` — `Joi.object({ ... })` with your env var definitions\n- `env` — environment source (defaults to `process.env`)\n- Throws `Error` if validation fails\n\nReturns `Config<T>` with:\n- `get(key)` — returns the value for a single key\n- `getAll()` — returns all validated values as an object\n\n### `setMockEnvValue(key, value)`\n\nSets a mock value for testing. While any mocks are set, all `createConfig()` calls skip validation.\n\n### `clearMockEnvValues()`\n\nClears all mocks, restoring normal validation behavior.\n\n## License\n\nMIT\n","readmeFilename":"README.md"}