Coding task · NestJS course · Module 1: NestJS Basics

Injection with Tokens

Use a token to inject configuration into a service.

Task

Define a configProvider constant with provide: 'CONFIG_TOKEN' and useValue holding a configuration object (e.g. { legion: 'Legio X Equestris' }) and add it to the providers of AppModule. Write a LegionConfigService that injects this value through the constructor with the @Inject('CONFIG_TOKEN') decorator and returns it from a getConfig() method.