
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
node-graceful-shutdown
Advanced tools
Gracefully handle your modular NodeJS application's shutdown (termination), using dependencies.
Process signals captured: SIGINT
, SIGTERM
, SIGQUIT
.
It doesn't matter in which order and where you define these graceful handlers, node-graceful-shutdown
will
handle them appropriately and exit the process once all of them are processed.
import { onShutdown } from "node-graceful-shutdown";
// module1.js
onShutdown("http-server", async function () {
// Stop your http server here.
});
// module2.js
onShutdown("message-bus", ["http-server"], async function () {
// Close your RabbitMQ connection here ONLY AFTER http server's onShutdown completed.
});
// moduleX.js
onShutdown("database", ["http-server", "message-bus"], async function () {
// Shut down your database here, ONLY AFTER http-server and message-bus are completed.
});
// After all handlers are processed without errors, process exits with code 0.
// Otherwise it exits with exit code 42759, or exit code 42758 if there are any errors in assigned shutdown handlers.
// If some of specified dependencies are not defined (like when "http-server" is missing in the above example),
// node-graceful-shutdown will run the current handler without waiting for the undefined dependency.
Or, if you have all your modules as exports and they all shutdown one after another,
this will work at its best in your application's main.js
:
import { onShutdown } from "node-graceful-shutdown";
import {
startModule1,
startModule2,
stopModule1,
stopModule2 /*, ...*/,
} from "./src";
export const startMyApp = async () => {
await startModule1();
await startModule2();
};
export const stopMyApp = async () => {
// Stop modules one after another.
await stopModule1();
await stopModule2();
// ...
};
// Handle application's shutdown.
onShutdown(stopMyApp);
This library, along existing ones, allow your application to be modular. You define a cleanup callback in-place, in the same module, where initialization happens. In addition, it allows specifying the order
Recommendations:
5.
).onShutdown
is application-wide (in terms of a single process), so the callbacks and their dependencies will see each other when imported from multiple files.onShutdownError
export which takes an error as an argument when any of assigned shutdown handlers throw an error (added for very-very prudent programmers only).SIGINT
, SIGTERM
, SIGQUIT
) if there are any. This is intended as other custom handlers can exit the process at any time.FAQs
Gracefully shutdown your modular NodeJS application
The npm package node-graceful-shutdown receives a total of 3,067 weekly downloads. As such, node-graceful-shutdown popularity was classified as popular.
We found that node-graceful-shutdown demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.