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.
Loading...
Related Quiz
- Which of the following is true about the prototype chain in JavaScript?
- The process.env object in Node.js contains the ________ variables of the environment where the Node.js process is executed.
- What is the main purpose of using mocking in unit testing?
- In Express, how can you enable Cross-Origin Resource Sharing (CORS) for your API?
- How can you ensure the reliability of your tests in a scenario where external services have inconsistent behavior?