Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Express middleware package.
Node.js
const express = require('[1]');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using core Node.js modules like 'http' instead of 'express'.
Misspelling the package name.
✗ Incorrect
The Express middleware package is imported using require('express').
2fill in blank
mediumComplete the code to use the middleware function in the Express app.
Node.js
app.[1](middlewareFunction); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using route methods like 'get' or 'post' instead of 'use'.
Trying to call 'listen' to add middleware.
✗ Incorrect
Use app.use() to apply middleware functions in Express.
3fill in blank
hardFix the error in the middleware function signature.
Node.js
function middleware(req, [1], next) { console.log('Middleware running'); next(); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'next' as the second parameter instead of the third.
Using incorrect parameter names.
✗ Incorrect
The middleware function parameters are req, res, and next.
4fill in blank
hardFill both blanks to import and use the 'cors' middleware in Express.
Node.js
const [1] = require('cors'); app.[2]([1]());
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'listen' instead of 'use' to apply middleware.
Importing the wrong package.
✗ Incorrect
Import 'cors' with require('cors') and use it with app.use(cors()).
5fill in blank
hardFill all three blanks to import, configure, and use the 'helmet' middleware with options.
Node.js
const [1] = require('helmet'); const helmetOptions = { contentSecurityPolicy: false }; app.[2]([1]([3]));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing 'cors' with 'helmet'.
Not passing options to the middleware function.
✗ Incorrect
Import 'helmet', then use app.use(helmet(helmetOptions)) to apply it with options.