Complete the code to import Express and create an app instance.
const express = require('[1]'); const app = express();
You need to import the 'express' module to create an Express app instance.
Complete the code to parse JSON data from incoming requests.
app.use([1].json());Express has built-in middleware to parse JSON, accessed via express.json().
Fix the error in the login route handler to correctly access the username from the request body.
app.post('/login', (req, res) => { const username = req.body[1]; res.send(`Hello, ${username}`); });
The username is expected to be sent in the request body under the 'username' key.
Fill both blanks to check if the password matches and send the correct response.
app.post('/login', (req, res) => { if (req.body.password [1] storedPassword) { res.status([2]).send('Login successful'); } else { res.status(401).send('Unauthorized'); } });
Use strict equality to compare passwords and send HTTP status 200 for success.
Fill all three blanks to create a middleware that logs the request method and URL, then calls next().
function logger(req, res, [1]) { console.log(req.[2] + ' ' + req.[3]); next(); }
Middleware functions receive 'next' as the third argument. Request method and URL are accessed via req.method and req.url.