I use @UseInterceptors with FilesInterceptor from @nestjs/platform-express. FilesInterceptor allows me to pass some configs (like files storage folder). I would like to pass not exact values (e.g. 'public') but to get them from configService.
From this answer (https://stackoverflow.com/a/59828094/13128344) I understood why calling this.configService from UseInterceptors results in undefined.
@UseInterceptors(FilesInterceptor('cat_pic', 2, this.configService.get('storageConfigs')))
So how can I pass configs to FilesInterceptor? Or how to access a service if I move file interceptor function to a separate module?
One option you have is to call config()
from the dotenv
package to load everything into process.env
in your main.ts
. You can still use the ConfigModule
and ConfigService
everywhere else, but in decorators you would use that process.env.storageConfigs
variable.
Another option would be a package like @golevelup/profiguration which is a configuration service that can be used in decorators because of the way it was written.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With