Complete the code to import the Express library.
const express = require('[1]');
The Express library is imported using require('express').
Complete the code to create a new Express application instance.
const app = [1]();You create an Express app by calling express().
Fix the error in the middleware function to correctly parse JSON requests.
app.use(express.[1]());To parse JSON request bodies, use express.json() middleware.
Fill both blanks to validate that the request body has a 'name' property before proceeding.
app.post('/submit', (req, res, next) => { if (!req.body.[1]) { return res.status([2]).send('Name is required'); } next(); });
The code checks if req.body.name exists. If not, it sends a 400 Bad Request status.
Fill all three blanks to create a middleware that validates 'email' and 'password' fields in the request body.
function validateUser(req, res, next) {
const { [1], [2] } = req.body;
if (![1] || ![2]) {
return res.status(400).send('Email and password are required');
}
next();
}The middleware extracts email and password from req.body and checks if both exist before continuing.
