Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@godaddy/terminus
Advanced tools
[![Build Status](https://travis-ci.org/godaddy/terminus.svg?branch=master)](https://travis-ci.org/godaddy/terminus)
@godaddy/terminus is a Node.js package that helps manage graceful shutdowns and health checks for your applications. It ensures that your application can handle termination signals properly, allowing for clean shutdowns and preventing data corruption or loss. It also provides endpoints for health checks to monitor the application's status.
Graceful Shutdown
This feature allows the application to handle termination signals gracefully. When a termination signal (e.g., SIGINT) is received, the `onSignal` function is called to perform any necessary cleanup before the server shuts down.
const http = require('http');
const { createTerminus } = require('@godaddy/terminus');
const server = http.createServer((req, res) => {
res.end('Hello world!');
});
function onSignal() {
console.log('Server is starting cleanup');
// start cleanup of resource, like databases or file descriptors
return Promise.resolve();
}
function onShutdown() {
console.log('Cleanup finished, server is shutting down');
}
createTerminus(server, {
signal: 'SIGINT',
onSignal,
onShutdown
});
server.listen(3000);
Health Checks
This feature provides a health check endpoint that can be used to monitor the application's status. The `onHealthCheck` function can include logic to determine if the application is healthy and return a promise that resolves if it is.
const http = require('http');
const { createTerminus } = require('@godaddy/terminus');
const server = http.createServer((req, res) => {
res.end('Hello world!');
});
function onHealthCheck() {
return Promise.resolve(); // optionally include a health check here
}
createTerminus(server, {
healthChecks: {
'/healthcheck': onHealthCheck
}
});
server.listen(3000);
express-graceful-exit is a middleware for Express.js applications that allows for graceful shutdowns. It provides similar functionality to @godaddy/terminus by enabling the application to handle termination signals and complete ongoing requests before shutting down. However, it is specifically designed for Express.js applications, whereas @godaddy/terminus can be used with any Node.js HTTP server.
lightship is a library for managing graceful shutdowns and health checks in Node.js applications. It offers similar features to @godaddy/terminus, including handling termination signals and providing health check endpoints. One key difference is that lightship includes built-in support for Kubernetes readiness and liveness probes, making it a good choice for applications running in Kubernetes environments.
Adds graceful shutdown and Kubernetes readiness / liveness checks for any HTTP applications.
const http = require('http');
const terminus = require('@godaddy/terminus');
function onSigterm () {
console.log('server is starting cleanup');
return Promise.all([
// your clean logic, like closing database connections
]);
}
function onShutdown () {
console.log('cleanup finished, server is shutting down');
}
const server = http.createServer((request, response) => {
response.end('<html><body><h1>Hello, World!</h1></body></html>');
})
terminus(server, {
// healtcheck options
healthChecks: {
'/healthcheck': check // a promise indicating service health
},
// cleanup options
timeout: 1000, // [optional = 5000] number of milliseconds before forcefull exiting
onSigterm, // [optional] clenaup function, returning a promise
onShutdown, // [optional] called right before exiting
// both
logger // [optional] logger function to be called with errors
});
server.listen(PORT);
const http = require('http');
const app = express();
app.get('/', (req, res) => {
res.send('ok');
});
const server = http.createServer(app);
terminus(server, {
//opts
});
server.listen(3000);
const http = require('http');
const Koa = require('koa');
const app = new Koa();
const server = http.createServer(app.callback());
terminus(server, {
//opts
});
server.listen(3000);
FAQs
[![Join Slack](https://img.shields.io/badge/Join%20us%20on-Slack-e01563.svg)](https://godaddy-oss.slack.com/) [![Build Status](https://github.com/godaddy/terminus/actions/workflows/cicd.yml/badge.svg)](https://github.com/godaddy/terminus/actions/workflows
We found that @godaddy/terminus demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 11 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.