0
0
Node.jsframework~10 mins

Third-party middleware usage in Node.js - Interactive Code Practice

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

Complete the code to import the Express middleware package.

Node.js
const express = require('[1]');
Drag options to blanks, or click blank then click option'
Ahttp
Bpath
Cfs
Dexpress
Attempts:
3 left
💡 Hint
Common Mistakes
Using core Node.js modules like 'http' instead of 'express'.
Misspelling the package name.
2fill in blank
medium

Complete 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'
Aget
Blisten
Cuse
Dpost
Attempts:
3 left
💡 Hint
Common Mistakes
Using route methods like 'get' or 'post' instead of 'use'.
Trying to call 'listen' to add middleware.
3fill in blank
hard

Fix 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'
Aresponse
Bres
Cnext
Drequest
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'next' as the second parameter instead of the third.
Using incorrect parameter names.
4fill in blank
hard

Fill 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'
Acors
Blisten
Cuse
Dexpress
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'listen' instead of 'use' to apply middleware.
Importing the wrong package.
5fill in blank
hard

Fill 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'
Ahelmet
Buse
ChelmetOptions
Dcors
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing 'cors' with 'helmet'.
Not passing options to the middleware function.