Complete the code to create a NestJS hybrid application that supports both HTTP and WebSocket.
import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; async function bootstrap() { const app = await NestFactory.[1](AppModule); await app.listen(3000); } bootstrap();
The NestFactory.create() method creates a NestJS application that supports HTTP by default. To support WebSocket, you need to enable a WebSocket adapter separately.
Complete the code to enable WebSocket adapter in a NestJS hybrid application.
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();
The IoAdapter is the built-in WebSocket adapter for Socket.IO in NestJS.
Fix the error in the code to properly create a hybrid application with HTTP and microservice support.
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();
The Transport enum is imported and used with uppercase 'T' to specify the transport type.
Fill both blanks to create a NestJS hybrid app that connects a Redis microservice and listens on port 4000.
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();
Use create to create the main app and Transport.REDIS to specify Redis microservice transport.
Fill all three blanks to create a hybrid app with HTTP, connect a TCP microservice, and start both on port 5000.
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();
Use create to create the app, Transport.TCP for TCP microservice, and listen to start the HTTP server.