Complete the code to create an Express server that listens on port 3000.
const express = require('express'); const app = express(); app.get('/', (req, res) => res.send('Hello World!')); app.listen([1], () => console.log('Server running'));
The server listens on port 3000, which is a common default for Express apps.
Complete the code to gracefully close the server on shutdown.
const server = app.listen(3000); process.on('SIGTERM', () => { server.[1](() => { console.log('Server closed'); }); });
The close method stops the server from accepting new connections and waits for existing connections to finish.
Fix the error in the code to handle new connections during zero-downtime deployment.
const http = require('http'); const server = http.createServer(app); server.listen(3000); server.on('connection', (socket) => { socket.[1] = false; });
The destroyed property indicates if the socket is destroyed. Setting it to false means the socket is active.
Fill both blanks to track active connections and close them on shutdown.
const connections = new Set(); server.on('connection', (socket) => { connections.[1](socket); socket.on('close', () => connections.[2](socket)); });
Use add to add sockets to the set and delete to remove them when closed.
Fill all three blanks to close all active connections during server shutdown.
process.on('SIGTERM', () => { server.[1](() => console.log('Server closed')); for (const socket of connections) { socket.[2](); connections.[3](socket); } });
Call close on the server, destroy on each socket to close it, and delete to remove the socket from the set.