0
0
Expressframework~10 mins

Request ID for tracing in Express - 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 module.

Express
const express = require('[1]');
Drag options to blanks, or click blank then click option'
Aexpress
Bhttp
Cfs
Dpath
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'http' instead of 'express' to import the framework.
2fill in blank
medium

Complete the code to add a middleware that assigns a unique request ID.

Express
app.use((req, res, next) => {
  req.id = [1]();
  next();
});
Drag options to blanks, or click blank then click option'
Aconsole.log
BDate.now
Cuuid.v4
DMath.random
Attempts:
3 left
💡 Hint
Common Mistakes
Using Date.now or Math.random which are not guaranteed unique.
3fill in blank
hard

Fix the error in the code to correctly import the UUID v4 function.

Express
const { [1] } = require('uuid');
Drag options to blanks, or click blank then click option'
Auuidv4
Bv4
Cuuid
DuuidV4
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'uuidv4' or 'uuidV4' which are not exported names.
4fill in blank
hard

Fill both blanks to log the request ID and method in the middleware.

Express
app.use((req, res, next) => {
  console.log('Request ID:', req.[1], 'Method:', req.[2]);
  next();
});
Drag options to blanks, or click blank then click option'
Aid
Bmethod
Curl
Dbody
Attempts:
3 left
💡 Hint
Common Mistakes
Using req.url or req.body instead of req.method.
5fill in blank
hard

Fill all three blanks to create a middleware that adds a request ID header and logs it.

Express
app.use((req, res, next) => {
  const id = [1]();
  req.[2] = id;
  res.setHeader('[3]', id);
  next();
});
Drag options to blanks, or click blank then click option'
Av4
Bid
CX-Request-ID
Duuid
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong header name or not assigning the ID to req.id.