0
0
NestJSframework~20 mins

gRPC transport in NestJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
gRPC Transport Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this NestJS gRPC service call?

Consider a NestJS gRPC service with this method:

async getHello(): Promise<{ message: string }> { return { message: 'Hello from gRPC!' }; }

If a client calls getHello, what will the client receive?

NestJS
async getHello(): Promise<{ message: string }> { return { message: 'Hello from gRPC!' }; }
AA JSON object with a 'message' property containing 'Hello from gRPC!'
BA plain string 'Hello from gRPC!'
CAn error because gRPC does not support returning objects
DAn empty response with no data
Attempts:
2 left
💡 Hint

gRPC methods typically return objects matching the protobuf message structure.

📝 Syntax
intermediate
2:00remaining
Which option correctly configures a NestJS microservice to use gRPC transport?

Choose the correct code snippet to create a NestJS microservice using gRPC transport with package 'hero' and proto file 'hero.proto'.

Aapp.createMicroservice({ transport: Transport.GRPC, options: { package: 'hero', protoPath: 'hero.proto' } });
Bapp.connectMicroservice({ transport: Transport.GRPC, options: { package: 'hero', protoPath: 'hero.proto' } });
Capp.connectMicroservice({ transport: Transport.TCP, options: { package: 'hero', protoPath: 'hero.proto' } });
Dapp.createMicroservice({ transport: Transport.HTTP, options: { package: 'hero', protoPath: 'hero.proto' } });
Attempts:
2 left
💡 Hint

Use connectMicroservice with Transport.GRPC for gRPC microservices.

🔧 Debug
advanced
2:00remaining
What error occurs if the protoPath is incorrect in NestJS gRPC microservice config?

If you configure a NestJS gRPC microservice with a wrong protoPath that does not exist, what error will you see when starting the app?

ASyntaxError: Unexpected token in proto file
BTypeError: Cannot read property 'package' of undefined
CError: ENOENT: no such file or directory, open 'wrong.proto'
DNo error, the app starts normally
Attempts:
2 left
💡 Hint

Check the file path carefully when loading proto files.

state_output
advanced
2:00remaining
What is the value of the variable after this gRPC client call in NestJS?

Given this client call:

const response = await client.send<{ message: string }>('getHello', {}).toPromise();

What is the value of response.message if the server returns { message: 'Hi there!' }?

NestJS
const response = await client.send<{ message: string }>('getHello', {}).toPromise();
Anull
BAn error is thrown
Cundefined
D'Hi there!'
Attempts:
2 left
💡 Hint

The client receives the server's response object.

🧠 Conceptual
expert
2:00remaining
Which statement best describes the role of protobuf in NestJS gRPC transport?

Choose the most accurate description of how protobuf works with NestJS gRPC transport.

AProtobuf defines the message and service structure used to serialize and deserialize data between client and server.
BProtobuf is a database technology used to store gRPC messages persistently.
CProtobuf is a UI framework for building gRPC client interfaces.
DProtobuf automatically generates REST endpoints from gRPC services in NestJS.
Attempts:
2 left
💡 Hint

Think about what protobuf files describe in gRPC communication.