SIGTERM in Node.js

As an example, if you want to handle SIGTERM in Node.js, then you can use the process module that is implicitly created in every Node.js process to handle the signals and to exit the application. To match the preceding Python example, a simple shut down immediately and exit bit of code might be as follows:

/** * SIGTERM handler to terminate (semi) gracefully */process.on(process.SIGTERM, function() {    console.log('Received SIGTERM signal, now shutting down...');    process.exit(0);})

Get Kubernetes for Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.