Complete the code to import the Express library.
const express = require('[1]');
The Express library is imported using require('express').
Complete the code to parse JSON body data in Express.
app.use(express.[1]());To parse JSON body data, use express.json() middleware.
Fix the error in the route handler to access the 'username' field from the request body.
app.post('/login', (req, res) => { const username = req.body[1]; res.send(`Hello, ${username}`); });
To access the 'username' field from the body, use req.body['username'] or req.body.username. Here, the blank expects bracket notation.
Fill both blanks to validate that the 'email' field exists and is a string.
if (typeof req.body[1] === '[2]') { res.send('Valid email'); } else { res.status(400).send('Invalid email'); }
Use req.body['email'] to access the email field and check if its type is 'string'.
Fill all three blanks to create a middleware that checks if 'password' exists and is at least 6 characters long.
function validatePassword(req, res, next) {
const pwd = req.body[1];
if (typeof pwd === '[2]' && pwd.length [3] 6) {
next();
} else {
res.status(400).send('Password too short');
}
}Access the password with req.body['password'], check if it is a 'string', and verify length is at least 6 using >=.