Custom db logger service with TypeOrmModule.forRootAsync()
See original GitHub issue
[ ] Regression
[ ] Bug report
[ ] Feature request
[X] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
I have a custom DB module to initialize TypeOrm (= Nestjs’s TypeOrmModule). I want to pass an TypeormLoggerService (which relies on an app-wide LoggerService). This is the code:
db.module.ts:
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { TypeormLoggerService } from './typeorm-logger.service';
@Module({
controllers: [],
providers: [],
imports: [
TypeOrmModule.forRootAsync({
inject: [TypeormLoggerService],
useFactory: async (typeormLoggerService: TypeormLoggerService): Promise<any> => ({
type: 'sqlite',
database: `var/nest.db`,
entities: [`src/**/**.entity{.ts,.js}`],
logger: typeormLoggerService,
logging: true
}),
})
]
})
export class DbModule {}
Node crashes with the following error:
1: node::Abort() [/usr/local/bin/node]
2: node::Chdir(v8::FunctionCallbackInfo<v8::Value> const&) [/usr/local/bin/node]
3: v8::internal::FunctionCallbackArguments::Call(void (*)(v8::FunctionCallbackInfo<v8::Value> const&)) [/usr/local/bin/node]
4: v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) [/usr/local/bin/node]
5: v8::internal::Builtin_Impl_HandleApiCall(v8::internal::BuiltinArguments, v8::internal::Isolate*) [/usr/local/bin/node]
6: 0x1776425042fd
Environment
nest/typeorm version: 5.2.2
nest/common version: 5.3.5
nest/core version: 5.3.4
Issue Analytics
- State:
- Created 5 years ago
- Comments:16 (8 by maintainers)
Top Results From Across the Web
NestJS Using ConfigService with TypeOrmModule
How can I use this service with the the TypeOrmModule? TypeOrmModule.forRoot({ type: 'mysql', host: 'localhost', ...
Read more >API with NestJS #50. Introduction to logging with the built-in ...
We need a way to troubleshoot the application. This article serves as an introduction to how we can keep logs with the built-in...
Read more >Database | NestJS - A progressive Node.js framework
The forRoot() method supports all the configuration properties exposed by the DataSource constructor from the TypeORM package. In addition, there are several ...
Read more >Creating Dynamic Modules in Nest JS Part-1
Lets say i have created sendGrid Module, AzureBlobModule or Database Module, These Module will be used by other Modules and sometime
Read more >Multiple Databases | Nestjs-query - Blog
Then setup multiple database connections. ... TypeOrmModule.forRootAsync({ name: SECRET_DB_CONNECTION, // you need to set the name here! imports: ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You are trying to inject
TypeormLoggerService
which is unavailable in theTypeOrmModule
. In order to provide it, you would have to import a module that exportsTypeormLoggerService
, for example:I had to export TypeormLoggerService from DbModule and import it in TypeOrmModule although TypeOrmModule is included in the Module of TypeormLoggerService (DbModule). That was a bit confusing. But now I understand and it’s working. Thanks a lot!