Complete the code to import the built-in Node.js module for handling HTTPS requests.
const https = require('[1]');
The https module is used to create secure servers and handle HTTPS requests in Node.js.
Complete the code to create a secure HTTPS server using Node.js.
const server = https.createServer({ key: privateKey, cert: certificate }, [1]);The second argument to https.createServer is a request listener function that handles incoming requests.
Fix the error in the code to properly handle user input securely.
app.post('/login', (req, res) => { const username = req.body.[1]; // process login });
The property username is commonly used to access the username field from the request body.
Fill both blanks to create a middleware that protects routes by checking authentication.
function authMiddleware(req, res, [1]) { if (!req.user) { return res.status([2]).send('Unauthorized'); } next(); }
The middleware function uses next to pass control and sends a 401 status code for unauthorized access.
Fill all three blanks to safely parse JSON input and handle errors in a Node.js server.
app.use(express.text()); app.post('/data', (req, res) => { try { const data = JSON.[1](req.body); res.send([2]); } catch ([3]) { res.status(400).send('Invalid JSON'); } });
Use JSON.parse to convert JSON string to object, store it in data, and catch errors with error.