0
0
NestJSframework~10 mins

TypeORM module setup in NestJS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the TypeORM module in a NestJS module.

NestJS
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '[1]';

@Module({
  imports: [TypeOrmModule.forRoot()],
})
export class AppModule {}
Drag options to blanks, or click blank then click option'
A@nestjs/typeorm
Btypeorm
C@nestjs/common
Dtypeorm-nestjs
Attempts:
3 left
💡 Hint
Common Mistakes
Importing from 'typeorm' directly instead of '@nestjs/typeorm'.
Using '@nestjs/common' for TypeORM import.
2fill in blank
medium

Complete the code to configure the TypeORM connection with a PostgreSQL database.

NestJS
TypeOrmModule.forRoot({
  type: '[1]',
  host: 'localhost',
  port: 5432,
  username: 'user',
  password: 'pass',
  database: 'testdb',
  entities: [],
  synchronize: true,
})
Drag options to blanks, or click blank then click option'
Amysql
Bsqlite
Cpostgres
Dmariadb
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'mysql' or 'sqlite' instead of 'postgres'.
Misspelling the database type string.
3fill in blank
hard

Fix the error in the entities array to include the User entity correctly.

NestJS
import { User } from './user.entity';

TypeOrmModule.forRoot({
  type: 'postgres',
  host: 'localhost',
  port: 5432,
  username: 'user',
  password: 'pass',
  database: 'testdb',
  entities: [[1]],
  synchronize: true,
})
Drag options to blanks, or click blank then click option'
A'User'
BUser
Cuser
DUserEntity
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the entity name as a string.
Using a variable name that is not imported.
4fill in blank
hard

Fill both blanks to import and register the User entity in the feature module.

NestJS
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { [1] } from './user.entity';

@Module({
  imports: [TypeOrmModule.forFeature([[2]])],
})
export class UserModule {}
Drag options to blanks, or click blank then click option'
AUser
BUserEntity
DUserModel
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for import and registration.
Using names not matching the entity class.
5fill in blank
hard

Fill all three blanks to inject the UserRepository and use it in the service constructor.

NestJS
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { [1] } from './user.entity';

@Injectable()
export class UserService {
  constructor(
    @InjectRepository([2])
    private readonly [3]: Repository<User>,
  ) {}
}
Drag options to blanks, or click blank then click option'
AUser
CuserRepository
DUserRepo
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for import and injection.
Naming the repository variable with uppercase or inconsistent style.