Complete the code to import the Express module.
const express = require('[1]');
The Express module is imported using require('express').
Complete the code to add a middleware that assigns a unique request ID.
app.use((req, res, next) => {
req.id = [1]();
next();
});Date.now or Math.random which are not guaranteed unique.Using uuid.v4() generates a unique request ID for tracing.
Fix the error in the code to correctly import the UUID v4 function.
const { [1] } = require('uuid');The correct import syntax is const { v4 } = require('uuid');.
Fill both blanks to log the request ID and method in the middleware.
app.use((req, res, next) => {
console.log('Request ID:', req.[1], 'Method:', req.[2]);
next();
});req.url or req.body instead of req.method.Request ID is stored in req.id and HTTP method in req.method.
Fill all three blanks to create a middleware that adds a request ID header and logs it.
app.use((req, res, next) => {
const id = [1]();
req.[2] = id;
res.setHeader('[3]', id);
next();
});req.id.The middleware generates a UUID with v4(), assigns it to req.id, and sets the X-Request-ID header.
