0
0
NestJSframework~10 mins

NestJS vs Express vs Fastify comparison - Interactive Practice

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

Complete the code to create a basic NestJS controller method that handles GET requests.

NestJS
import { Controller, [1] } from '@nestjs/common';

@Controller('hello')
export class HelloController {
  @[1]()
  getHello() {
    return 'Hello World!';
  }
}
Drag options to blanks, or click blank then click option'
AGet
BPost
CPut
DDelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Post instead of @Get for GET requests.
Forgetting to import the decorator from '@nestjs/common'.
2fill in blank
medium

Complete the code to create an Express route handler that responds with 'Hello Express!'.

NestJS
import express from 'express';
const app = express();

app.[1]('/', (req, res) => {
  res.send('Hello Express!');
});
Drag options to blanks, or click blank then click option'
Aget
Bput
Cpost
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using app.post instead of app.get for GET requests.
Forgetting to call res.send() to send a response.
3fill in blank
hard

Fix the error in the Fastify route registration to correctly handle GET requests.

NestJS
import Fastify from 'fastify';
const fastify = Fastify();

fastify.[1]('/', async (request, reply) => {
  return 'Hello Fastify!';
});
Drag options to blanks, or click blank then click option'
Aregister
Bget
Clisten
Dpost
Attempts:
3 left
💡 Hint
Common Mistakes
Using fastify.post instead of fastify.get for GET requests.
Using fastify.listen or fastify.register incorrectly as route handlers.
4fill in blank
hard

Fill both blanks to create a NestJS controller method that uses Express's response object to send JSON.

NestJS
import { Controller, Injectable, [1] } from '@nestjs/common';
import { Response } from 'express';

@Controller()
@Injectable()
export class AppController {
  @[1]()
  sendJson(res: [2]) {
    res.json({ message: 'Hello from NestJS with Express!' });
  }
}
Drag options to blanks, or click blank then click option'
ARes
BRequest
CResponse
DReq
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Request or @Req instead of @Res for response injection.
Using wrong type like Request instead of Response.
5fill in blank
hard

Fill all three blanks to create a Fastify route with schema validation and a handler that returns a greeting.

NestJS
fastify.route({
  method: '[1]',
  url: '/greet',
  schema: {
    querystring: {
      type: 'object',
      properties: {
        name: { type: 'string' }
      },
      required: ['[2]']
    }
  },
  handler: async (request, reply) => {
    const name = request.query.[3];
    return { greeting: `Hello, ${name}!` };
  }
});
Drag options to blanks, or click blank then click option'
Aget
Bname
Dpost
Attempts:
3 left
💡 Hint
Common Mistakes
Using POST method instead of GET for this route.
Mismatching required query parameter name and property accessed.