{"id":18974982,"url":"https://github.com/bufferapp/buffer-js-shutdown-helper","last_synced_at":"2025-04-19T16:44:25.595Z","repository":{"id":65840760,"uuid":"77945255","full_name":"bufferapp/buffer-js-shutdown-helper","owner":"bufferapp","description":"Shutdown your Express.js apps gracefully","archived":false,"fork":false,"pushed_at":"2017-05-08T20:05:24.000Z","size":8,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":32,"default_branch":"master","last_synced_at":"2025-04-09T12:04:36.293Z","etag":null,"topics":["expressjs","shutdown-helper"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bufferapp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-03T19:11:55.000Z","updated_at":"2017-11-27T15:30:35.000Z","dependencies_parsed_at":"2023-02-13T14:10:12.687Z","dependency_job_id":null,"html_url":"https://github.com/bufferapp/buffer-js-shutdown-helper","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bufferapp%2Fbuffer-js-shutdown-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bufferapp%2Fbuffer-js-shutdown-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bufferapp%2Fbuffer-js-shutdown-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bufferapp%2Fbuffer-js-shutdown-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bufferapp","download_url":"https://codeload.github.com/bufferapp/buffer-js-shutdown-helper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249223960,"owners_count":21232841,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["expressjs","shutdown-helper"],"created_at":"2024-11-08T15:16:52.510Z","updated_at":"2025-04-16T09:34:25.391Z","avatar_url":"https://github.com/bufferapp.png","language":"JavaScript","readme":"# @bufferapp/shutdown-helper\n\n[![NPM Version](https://img.shields.io/npm/v/@bufferapp/shutdown-helper.svg)](https://www.npmjs.com/package/@bufferapp/shutdown-helper)\n[![Build Status](https://travis-ci.org/bufferapp/node-shutdown-helper.svg?branch=master)](https://travis-ci.org/bufferapp/node-shutdown-helper)\n\nProvides a basic helper that listens to the `SIGTERM` signal and will shutdown the given\n[Express.js](http://expressjs.com/) server after the given delay in seconds.\n\n## Install\n\n```\nnpm install @bufferapp/shutdown-helper -SE\n```\n\n## Usage\n\nTo use with your Express.js app, you'll have to use Node's `http` package to start your server.\nHere is a full usage example:\n\n```js\nconst http = require('http')\nconst express = require('express')\nconst shutdownHelper = require('@bufferapp/shutdown-helper')\nconst createLogger = require('@bufferapp/logger')\n\nconst shutdownDelay = 20 // seconds\n\nconst logger = createLogger({ name: 'Images-Worker' })\nconst app = express()\nconst server = http.createServer(app)\n\nserver.listen(8080)\n\nshutdownHelper.init({ server, shutdownDelay, logger })\n```\n\nThe `init` function takes one argument with the following options:\n\n- `server` ([*http.Server*](https://nodejs.org/dist/latest-v6.x/docs/api/http.html#http_class_http_server)) -\n  An instance of a Node http server\n- `shutdownDelay` (*Integer*) - The delay in seconds after which to shut down the http server. Default `20` seconds.\n- `logger` (*@bufferapp/logger*) - (optional) - If passed in log messages to [`@bufferapp/logger`](https://github.com/bufferapp/node-logger) otherwise logged to `console`\n\nElsewhere in your application, ideally in a health-check endpoint, you can use the `isShutingDown`\nfunction to check if your application has received a `SIGTERM`:\n\n```js\nconst { isShutingDown } = require('@bufferapp/shutdown-helper')\n\napp.get('/health-check', (req, res) =\u003e {\n  const code = isShutingDown() ? 500 : 200\n  const status = code === 200 ? 'awesome' : 'shutting down'\n  res.status(code).json({ status })\n})\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbufferapp%2Fbuffer-js-shutdown-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbufferapp%2Fbuffer-js-shutdown-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbufferapp%2Fbuffer-js-shutdown-helper/lists"}