terminate
A reliable (tested) way to Terminate a Node.js Process (and all Child Processes) based on the Process ID
Usage
Install from NPM
npm install terminate --save
In your script
var terminate = require('terminate');
terminate(process.pid, function(err, done){
if(err) {
console.log("Oopsy: " + err);
}
else {
console.log(done);
}
})
tl;dr
Why?
In our Faster project
we run the server using a child process.
When we want to re-start the server,
we needed to ensure the process (and any Child Processes)
were Terminateed before re-start.
Research
Background Reading
Useful StackOverflow Questions/Answers
Background / Motivation
While building the Faster
module we decided to use Child Process(es)
to run the application we are observing.
As a result, we need to be able to kill those processes in order to re-start the app.
Why not use an Existing Module?
We investigated using terminate: https://github.com/indexzero/terminate/
it was un-maintained and had no tests
so we submitted an issue
offering to update the module with tests.
Charlie
replied welcoming an update so we submitted
a Pull Request
with 100% test coverage
Other potential modules:
Name
Terminate
seemed like the best (of the available) name,
if you have a better suggestion, please share!
## This Project Reminded me of Two *xkcd* Comics: