0
0
Node.jsframework~10 mins

Graceful shutdown handling in Node.js - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to listen for the shutdown signal.

Node.js
process.on('[1]', () => {
  console.log('Shutdown signal received');
});
Drag options to blanks, or click blank then click option'
ASIGINT
BSTART
CRUN
DEXIT
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'EXIT' instead of 'SIGINT' for the shutdown signal.
Confusing signal names like 'START' or 'RUN'.
2fill in blank
medium

Complete the code to close the HTTP server on shutdown.

Node.js
server.[1](() => {
  console.log('Server closed');
});
Drag options to blanks, or click blank then click option'
Aclose
Bstop
Cshutdown
Dend
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'stop' or 'shutdown' which are not valid server methods.
Using 'end' which is for streams, not servers.
3fill in blank
hard

Fix the error in the shutdown handler to exit the process after closing the server.

Node.js
process.on('SIGTERM', () => {
  server.close(() => {
    [1](0);
  });
});
Drag options to blanks, or click blank then click option'
Aclose
Bstop
Cshutdown
Dexit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'stop' or 'shutdown' which are not Node.js process methods.
Using 'close' which is a server method, not a process method.
4fill in blank
hard

Fill both blanks to handle multiple shutdown signals and close the server.

Node.js
['SIGINT', '[1]'].forEach(signal => {
  process.on(signal, () => {
    server.[2](() => {
      console.log(`${signal} received, server closed.`);
      process.exit(0);
    });
  });
});
Drag options to blanks, or click blank then click option'
ASIGTERM
BSIGSTART
Cshutdown
Dclose
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid signal names like 'SIGSTART'.
Using wrong server methods like 'shutdown' instead of 'close'.
5fill in blank
hard

Fill all three blanks to log shutdown start, close server, and log shutdown complete.

Node.js
process.on('SIGINT', () => {
  console.log('[1]');
  server.[2](() => {
    console.log('[3]');
    process.exit(0);
  });
});
Drag options to blanks, or click blank then click option'
AShutdown starting
Bclose
CShutdown complete
DShutdown failed
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong messages that don't match the shutdown steps.
Using wrong server methods like 'stop' instead of 'close'.