Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Express library.
Express
const express = require('[1]');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'http' instead of 'express'
Using 'router' which is part of Express but not the main import
✗ Incorrect
The Express library is imported using require('express').
2fill in blank
mediumComplete the code to create a new Express app instance.
Express
const app = [1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'router()' which is for routing, not app creation
Using 'listen()' which starts the server, not creates the app
✗ Incorrect
You create an Express app by calling express().
3fill in blank
hardFix the error in the route definition to respond with 'Hello World'.
Express
app.get('/hello', (req, res) => { res.[1]('Hello World'); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.write which does not end the response
Using res.json which sends JSON, not plain text
✗ Incorrect
The res.send() method sends a response body as plain text.
4fill in blank
hardFill both blanks to document the GET endpoint with Swagger.
Express
/** * @swagger * /users: * [1]: * description: Get all users * responses: * 200: * description: Success */
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase HTTP methods
Using wrong HTTP verbs like post or put
✗ Incorrect
The Swagger documentation uses lowercase HTTP methods like get to describe endpoints.
5fill in blank
hardFill all three blanks to add a Swagger parameter for user ID in the path.
Express
/**
* @swagger
* /users/{id}:
* get:
* parameters:
* - in: [1]
* name: [2]
* required: true
* schema:
* type: [3]
*/ Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'query' instead of 'path' for path parameters
Using wrong parameter name or type
✗ Incorrect
In Swagger, path parameters are declared with in: path, the parameter name, and its type.