You are developing a Node.js application that should gracefully shut down when it receives a termination signal. How would you accomplish this using the process object?

  • process.on('terminate', () => { /* Graceful shutdown code */ });
  • process.kill('SIGTERM', process.pid);
  • process.exit(0);
  • process.handleTermination(() => { /* Graceful shutdown code */ });
To gracefully shut down a Node.js application upon receiving a termination signal, you should use process.on('terminate', () => { /* Graceful shutdown code */ });. This registers an event handler for the 'terminate' event. The other options either do not handle termination signals gracefully or are incorrect syntax.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *