Complete the code to import the Express module.
const express = require('[1]');
The Express module is imported using require('express'). This allows you to create an Express app.
Complete the code to create a new Express application instance.
const app = [1]();Calling express() creates a new Express app instance to handle requests.
Fix the error in the code to log the response time using middleware.
app.use((req, res, next) => {
const start = Date.now();
res.on('finish', () => {
console.log(`Response time: ${Date.now() - [1]ms`);
});
next();
});The variable start holds the start time. Subtracting it from the current time gives the response duration.
Fill both blanks to create a middleware that measures and logs request duration in milliseconds.
app.use((req, res, next) => {
const [1] = Date.now();
res.on('[2]', () => {
console.log(`Request took ${Date.now() - start}ms`);
});
next();
});The variable start stores the start time. The event 'finish' fires when the response is done, so logging then shows total request time.
Fill all three blanks to create a simple route that responds with 'OK' and logs the request method and URL.
app.[1]('/status', (req, res) => { console.log(`[2] request to [3]`); res.send('OK'); });
req.method and req.url in the log message changes meaning.The route uses get to handle GET requests. req.method gives the HTTP method, and req.url gives the requested URL.