4.5.3 • Published 5 months ago

@newtral/nestjs-configuration v4.5.3

Weekly downloads
97
License
MIT
Repository
github
Last release
5 months ago

@newtral/nestjs-configuration

Usage

Assume you have the following .env file. The .env file is loaded into an object using the dotenv package.

USER_EXTERNAL_ENDPOINT=https://api.exaple.com/users
import { ConfigurationModule } from '@newtral/nestjs-configuration';
import { Injectable, Module } from '@nestjs/common';

// Define a valid JSON schema for your configuration object
const { InjectConfiguration, configurationModule } = ConfigurationModule.forEnvironment({
  type: 'object',
  properties: {
    USER_EXTERNAL_ENDPOINT: { type: 'string' }
  },
  required: ['USER_EXTERNAL_ENDPOINT']
});

@Injectable()
class UserService {
  constructor(@InjectConfiguration('USER_EXTERNAL_ENDPOINT') private readonly endpoint: string) {}
}

@Module({
  imports: [configurationModule],
  providers: [UserService]
})
class AppModule {}

ConfigurationModule.forEnvironment(schema: JSONSchema7)

  • schema: A valid JSON Schema v7

InjectConfiguration(configurationKey?: string)

  • When no configurationKey is provided the whole configuration object is injected
  • When the configurationKey is provided the only the selected configuration key is injected

Development

The project use husky and lint-staged for linting and fixing possible errors on source code before commit

Git hooks scripts are installed after running npm install the first time

npm run build:commonjs

Compile typescript files from the src folder inside the lib folder

npm run build:esm

Compile typescript files from the src folder inside the esm folder using es modules

npm run build

Concurrently run both build:commonjs and build:esm

npm run clean

Remove the following directories/files

  • lib
  • esm
  • reports

npm test

Run tests files inside the tests folder that matches the following patterns. Exit with code > 0 on error

  • *.test.ts
  • *.spec.ts

npm run cover

The same as npm test and generates coverages reports in reports/coverage. Exit with code > 0 on error

npm run lint

Check eslint errors according to .eslintrc

npm run lint:fix

Run npm run lint applying fixes and run prettier on every typescript file

npm run health

Check for:

  • Build errors
  • Tests failures
  • Lint errors

npm run ci

Run test and generate every possible report. Do not exit with error code > 0 if the tests fail. It generates a report file instead

  • reports/lint-checkstyle.xml Lint report in chackstyle format
  • reports/test-results.xml Test report in xUnit format
  • reports/coverage/clover.xml Coverage report in clover format
  • reports/coverage/cobertura-coverage.xml Coverage report in cobertura format
  • reports/coverage/lcov.info Coverage report in lcov
  • reports/coverage/index.html Coverage report in html
4.5.3

5 months ago

4.5.0

5 months ago

4.4.0

5 months ago

4.5.2

5 months ago

4.2.0

2 years ago

4.1.0

2 years ago

4.0.1

3 years ago

4.0.0

3 years ago

3.1.1

3 years ago

3.1.0

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.0.0

3 years ago

1.3.0

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago