In my Nest js app, This is the code of the app.controller:
@Controller('app')
export class AppController {
constructor(private readonly appService: AppService) {}
@Get('/:id')
getHello(@Param('id') id: string): string {
console.log(id);
return this.appService.getHello();
}
}
It works perfect using the request: localhost:3000/app/1
When I add a functionality in my app.module to work with Postgres:
@Module({
imports: [
UsersModule,
ScheduleModule.forRoot(),
CacheModule.register({ isGlobal: true }),
HttpModule,
ConfigModule.forRoot({
isGlobal: true,
envFilePath: ['.env.dev'],
}),
TypeOrmModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (configService: ConfigService) => ({
type: 'postgres',
autoLoadEntities: true,
synchronize: true,
host: configService.get('DB_HOST'),
port: configService.get('DB_PORT'),
username: configService.get('DB_USERNAME'),
password: configService.get('DB_PASSWORD'),
database: configService.get('DB_DATABASE'),
}),
}),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
The application is running, but I see that when I call to: localhost:3000/app/1 it gets to my controller with "undefined" in the param.
I will appreciate any help. Thanks!
Typeorm updated their version of
reflect-metadatato0.2.1recently. Nest is compatible with it, but you need to update your application's version of it to match. Simply run your package manager'sinstallcommand with the target asreflect-metadata@^0.2and everything should be fine.