Recall & Review
beginner
What is a graceful shutdown in Node.js?
A graceful shutdown means stopping the Node.js app carefully by finishing ongoing tasks and closing resources before exiting, so no data is lost or corrupted.
Click to reveal answer
beginner
Why should you handle errors during shutdown in Node.js?
Handling errors during shutdown helps avoid crashes and ensures the app cleans up resources like database connections or servers properly before stopping.
Click to reveal answer
intermediate
Which Node.js events are commonly used to trigger graceful shutdown?
The 'SIGINT' and 'SIGTERM' signals are used to start graceful shutdown, and 'uncaughtException' or 'unhandledRejection' events handle unexpected errors.
Click to reveal answer
intermediate
What is the role of process.exit() in graceful shutdown?
process.exit() stops the Node.js process. In graceful shutdown, it is called only after all cleanup tasks finish to avoid abrupt termination.
Click to reveal answer
intermediate
How can you ensure database connections close during a graceful shutdown?
You call the database client's close or disconnect method inside the shutdown handler to close connections before the app exits.
Click to reveal answer
Which event should you listen to for catching unexpected errors in Node.js?
✗ Incorrect
The 'uncaughtException' event catches errors not handled anywhere else in the code.
What does a graceful shutdown NOT do?
✗ Incorrect
Graceful shutdown avoids immediately killing the process to prevent data loss.
Which signal is commonly sent to a Node.js app to request shutdown?
✗ Incorrect
SIGINT is sent when you press Ctrl+C to stop the app.
What should you do before calling process.exit() during shutdown?
✗ Incorrect
Closing connections ensures no data is lost before exiting.
How can you handle promise rejections during shutdown?
✗ Incorrect
'unhandledRejection' catches promises that fail without a catch.
Explain how to implement a graceful shutdown in a Node.js app when an error occurs.
Think about stopping the app carefully without losing data.
You got /4 concepts.
Why is it important to handle errors during the shutdown process in Node.js?
Consider what happens if the app stops suddenly.
You got /4 concepts.