Complete the code to import the Express library.
const express = require([1]);The Express library is imported using require("express") to create an app.
Complete the code to start the server listening on port 3000.
const server = app.listen([1], () => { console.log('Server running'); });
Port 3000 is commonly used for local Express servers.
Fix the error in the shutdown handler to close the server properly.
process.on('SIGINT', () => { console.log('Shutting down...'); server.[1](() => { console.log('Server closed'); process.exit(0); }); });
The Express server instance has a close() method to stop accepting new connections.
Fill both blanks to handle server shutdown on SIGTERM signal.
process.on('[1]', () => { console.log('SIGTERM received'); server.[2](() => { console.log('Server closed on SIGTERM'); process.exit(0); }); });
SIGTERM is a termination signal. The server closes with close() method.
Fill all three blanks to log shutdown reason and close the server.
function gracefulShutdown(signal) {
console.log(`Received $[1] signal.`);
server.[2](() => {
console.log(`Server closed due to $[3]`);
process.exit(0);
});
}
process.on('SIGINT', () => gracefulShutdown('SIGINT'));
process.on('SIGTERM', () => gracefulShutdown('SIGTERM'));The function logs the signal name, closes the server with close(), and logs the signal reason.
