A knock at the door
An HTTP server that closes cleanly when it gets SIGTERM.
const http = require('node:http');const server = http.createServer();process.on('SIGTERM', () => { console.log('SIGTERM'); server.close(() => console.log('closed'));});process.on('exit', (code) => console.log('exit ' + code));server.listen(0, () => { console.log('listening'); process.kill(process.pid, 'SIGTERM');});1. Predict the output
Tap the lines in the order you think they print.
- 1…
- 2…
- 3…
- 4…