0
0
Node.jsframework~10 mins

Graceful shutdown on errors 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 uncaught exceptions and log the error.

Node.js
process.on('uncaughtException', (err) => {
  console.error('Uncaught Exception:', [1]);
});
Drag options to blanks, or click blank then click option'
Aerr.message
Berr
Cerror
Dexception
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name not defined in the callback.
Logging only err.message which hides stack trace.
2fill in blank
medium

Complete the code to listen for unhandled promise rejections and log the reason.

Node.js
process.on('unhandledRejection', (reason, promise) => {
  console.error('Unhandled Rejection at:', [1]);
});
Drag options to blanks, or click blank then click option'
Apromise
Bexception
Cerror
Dreason
Attempts:
3 left
💡 Hint
Common Mistakes
Logging the promise object instead of the reason.
Using undefined variable names.
3fill in blank
hard

Fix the error in the code to properly close the server on SIGINT signal.

Node.js
process.on('SIGINT', () => {
  console.log('SIGINT received, shutting down...');
  server.[1](() => {
    console.log('Server closed');
    process.exit(0);
  });
});
Drag options to blanks, or click blank then click option'
Aclose
Bshutdown
Cstop
Dend
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like shutdown or stop.
Not calling process.exit() after closing.
4fill in blank
hard

Fill both blanks to log the error and exit the process with failure code.

Node.js
process.on('uncaughtException', (err) => {
  console.error('Error:', [1]);
  process.[2](1);
});
Drag options to blanks, or click blank then click option'
Aerr
Bexit
Cabort
Dthrow
Attempts:
3 left
💡 Hint
Common Mistakes
Using process.abort() which causes a core dump.
Not exiting the process after an uncaught exception.
5fill in blank
hard

Fill all three blanks to handle SIGTERM by closing the server and exiting cleanly.

Node.js
process.on('[1]', () => {
  console.log('Signal received, closing server...');
  server.[2](() => {
    console.log('Server closed, exiting.');
    process.[3](0);
  });
});
Drag options to blanks, or click blank then click option'
ASIGTERM
Bclose
Cexit
DSIGINT
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing SIGINT with SIGTERM.
Not calling process.exit() after closing the server.