# tidy-exit

> Allow node apps to gracefully exit (allow exisitng requests to finish before shutting down)

Latest version **0.3.0** (published 2015-07-28) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install tidy-exit
pnpm add tidy-exit
yarn add tidy-exit
bun add tidy-exit
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2015-07-28 |
| First published | 2015-06-30 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Tarun Kothuri |
| Maintainers | tarunbk |
| Keywords | graceful exit, tidy exit, shutdown |

## Links

- npm: https://www.npmjs.com/package/tidy-exit
- Repository: https://github.com/tarun/tidy-exit
- Homepage: https://github.com/tarun/tidy-exit#readme
- Issues: https://github.com/tarun/tidy-exit/issues
- npm.io page: https://npm.io/package/tidy-exit

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.3.0 (latest) — 2015-07-28
- 0.2.0 — 2015-06-30

## README

[![Circle CI](https://circleci.com/gh/tarun/tidy-exit.svg?style=shield)](https://circleci.com/gh/tarun/tidy-exit)

# Introduction
 NodeJS Tidy Exit - api hooks to detect shutdown and perform cleanup actions for a graceful tidy application exit.

# Goal
Successfully finish processing in-progress requests before shutting down instead of abruptly abandoning them.

# Approach
* Listen to process shutdown events
* When  an event occurs
 * stop accepting new requests
 * close existing connections
 * wait to finish processing exisitng requests
* exit process after a timeout or when all requests are done

# Library Integration
* ExpressJS
* NodeJS Net Server

# Usage

    var tidy_exit = require('tidy-exit');

    tidy_exit.addTidyExitHandler(function(err, done) {
        console.log('Shutting down');
        done();
    });

    var app = express();
    var handle = tidy_exit.hookExpressApp(app);

    var server = http.createServer(app);
    var handle = tidy_exit.hookHttpServer(server);

    # if intentionally closing app before process shutdown (test cases, etc.)
    handle.close();


# Inspiration & References
[https://github.com/mathrawka/express-graceful-exit]()

[http://glynnbird.tumblr.com/post/54739664725/graceful-server-shutdown-with-node-js-and-express]()

[http://blog.argteam.com/coding/hardening-node-js-for-production-part-3-zero-downtime-deployments-with-nginx/]()

---
_Source: https://npm.io/package/tidy-exit · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
