Terminate a service as gracefully as possible on error; does not travel through time.


stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
00Jun 29, 2016Sep 30, 2015Minified + gzip package size for @microservice/koa-terminator in KB


microservice / terminator

shuts down the server if an error occurs. tries to be nice about it.


first, register the middleware

const terminator = require('@microservice/koa-terminator');

app.use(require('koa-error')); // catch errors and display error pages like normal
app.use(terminator()); // this will signal termination on uncaught errors
// everything else comes after

then, listen for a terminate event

const server = app.listen();

process.on('terminate', () => {
  // the process will exit once existing connections are done
  // you could use a timeout here to force shutdown as well.
  const timer = setTimeout(() => {
  }, 5000);

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.