# fastify-close-idle-server

> Fastify plugin that closes the server after no requests have been made for a specified amount of time.

Latest version **0.0.1** (published 2023-02-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install fastify-close-idle-server
pnpm add fastify-close-idle-server
yarn add fastify-close-idle-server
bun add fastify-close-idle-server
```

## 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.0.1 |
| Published | 2023-02-22 |
| First published | 2023-02-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 4.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Alex Bronstein |
| Maintainers | effulgentsia |
| Keywords | fastify, idle |

## Links

- npm: https://www.npmjs.com/package/fastify-close-idle-server
- Repository: https://github.com/effulgentsia/fastify-close-idle-server
- Homepage: https://github.com/effulgentsia/fastify-close-idle-server#readme
- Issues: https://github.com/effulgentsia/fastify-close-idle-server/issues
- npm.io page: https://npm.io/package/fastify-close-idle-server

## Dependencies (1)

- [fastify-plugin](https://npm.io/package/fastify-plugin.md) *

## 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.0.1 (latest) — 2023-02-22

## README

# fastify-close-idle-server

Fastify plugin to close the server after it's been idle (hasn't served any requests) for too long. This can be used as part of an application scaling solution, including scaling to zero.

## Install
```
npm i fastify-close-idle-server
```

## Usage
To use this plugin's default of calling `fastify.close()` after the server has been running for one consecutive minute without serving any requests:
```
const fastify = require('fastify')()
fastify.register(require('fastify-close-idle-server'))

// Register other plugins, add routes, etc. as normal.

fastify.listen({ port: 3000 })
```

To specify a different amount of idle time to wait before closing the server, set the `delay` option in milliseconds. For example, to close the server after 30 seconds of idle time:
```
fastify.register(require('fastify-close-idle-server'), {
  delay: 30000
})
```

This plugin's default close function, `fastify.close()`, does not exit the process unless you have added a separate [onClose hook](https://www.fastify.io/docs/latest/Reference/Hooks/#onclose) or other code to do that. To run a different close function, set the `closeFunction` option. For example, to run the close function returned by [closeWithGrace](https://github.com/mcollina/close-with-grace):
```
const {close} = require('close-with-grace')({ delay: 500 }, async function ({ signal, err, manual }) {
  await fastify.close()
})
fastify.register(require('fastify-close-idle-server'), {
  closeFunction: close
})
```

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