0
0
NestJSframework~10 mins

Hybrid applications 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 create a NestJS hybrid application that supports both HTTP and WebSocket.

NestJS
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.[1](AppModule);
  await app.listen(3000);
}
bootstrap();
Drag options to blanks, or click blank then click option'
AcreateMicroservice
BcreateHybridApplication
CcreateWebSocketAdapter
Dcreate
Attempts:
3 left
💡 Hint
Common Mistakes
Using createMicroservice instead of create for hybrid apps.
Trying to use a non-existent method like createHybridApplication.
2fill in blank
medium

Complete the code to enable WebSocket adapter in a NestJS hybrid application.

NestJS
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { IoAdapter } from '@nestjs/platform-socket.io';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.useWebSocketAdapter(new [1](app));
  await app.listen(3000);
}
bootstrap();
Drag options to blanks, or click blank then click option'
AWsAdapter
BIoAdapter
CSocketAdapter
DWebSocketAdapter
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent adapter like WsAdapter or WebSocketAdapter.
Not passing the app instance to the adapter constructor.
3fill in blank
hard

Fix the error in the code to properly create a hybrid application with HTTP and microservice support.

NestJS
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { Transport } from '@nestjs/microservices';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.connectMicroservice({ transport: [1].TCP });
  await app.startAllMicroservices();
  await app.listen(3000);
}
bootstrap();
Drag options to blanks, or click blank then click option'
ATransport
Btransport
CTRANSPORT
DTransporter
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'transport' which is undefined.
Using a wrong identifier like 'Transporter'.
4fill in blank
hard

Fill both blanks to create a NestJS hybrid app that connects a Redis microservice and listens on port 4000.

NestJS
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { Transport } from '@nestjs/microservices';

async function bootstrap() {
  const app = await NestFactory.[1](AppModule);
  app.connectMicroservice({ transport: [2].REDIS });
  await app.startAllMicroservices();
  await app.listen(4000);
}
bootstrap();
Drag options to blanks, or click blank then click option'
Acreate
BcreateMicroservice
CTransport
Dtransport
Attempts:
3 left
💡 Hint
Common Mistakes
Using createMicroservice instead of create for main app.
Using lowercase 'transport' instead of 'Transport'.
5fill in blank
hard

Fill all three blanks to create a hybrid app with HTTP, connect a TCP microservice, and start both on port 5000.

NestJS
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { Transport } from '@nestjs/microservices';

async function bootstrap() {
  const app = await NestFactory.[1](AppModule);
  app.connectMicroservice({ transport: [2].TCP });
  await app.startAllMicroservices();
  await app.[3](5000);
}
bootstrap();
Drag options to blanks, or click blank then click option'
Acreate
BTransport
Clisten
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'start' instead of 'listen' to start the HTTP server.
Using lowercase 'transport' instead of 'Transport'.