Package Exports
- terminate
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (terminate) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
terminate
A reliable (tested) way to Terminate a Node.js Process (and all Child Processes) based on the Process ID

[![Node.js Version][node-version-image]][node-version-url]
[node-version-image]: https://img.shields.io/node/v/listdirs.svg?style=flat
[node-version-url]: http://nodejs.org/download/
Usage
Install from NPM
npm install terminate --saveIn your script
var terminate = require('terminate');
terminate(process.pid, function(err, done){
if(err) { // you will get an error if you did not supply a valid process.pid
console.log("Oopsy: " + err); // handle errors in your preferred way.
}
else {
console.log(done); // do what you do best!
}
})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
- How to terminate node processes: https://github.com/joyent/node/issues/1172 (history lesson)
- nodejs exec command failing with no useful error message: https://github.com/joyent/node/issues/4590
Useful StackOverflow Questions/Answers
- http://stackoverflow.com/questions/26694100/why-does-my-node-app-process-keep-getting-stopped-when-i-use-forever
- http://stackoverflow.com/questions/18275809/kill-all-child-process-when-node-process-is-killed
- http://stackoverflow.com/questions/26004519/why-doesnt-my-node-js-process-terminate-once-all-listeners-have-been-removed
- http://stackoverflow.com/questions/14319724/nodejs-exec-command-failing-with-no-useful-error-message
- http://stackoverflow.com/questions/9275654/how-many-child-processes-can-a-node-js-cluster-spawn-on-a-64bit-wintel-pc
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:
- nexpect: https://github.com/nodejitsu/nexpect
- node-ps: https://github.com/neekey/ps (has basic tests but no cov)
- tree-kill: https://www.npmjs.com/package/tree-kill (no tests!!)
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:

