
Product
Introducing Module Reachability: Focus on the Vulnerabilities That Matter
Module Reachability filters out unreachable CVEs so you can focus on vulnerabilities that actually matter to your application.
A replacement for process.exit that ensures stdio are fully drained before exiting.
The 'exit' npm package is a simple utility that allows you to gracefully exit your Node.js process. It is particularly useful in situations where you need to ensure that all pending asynchronous operations complete before the process exits, such as closing database connections or cleaning up resources.
Graceful Exit
This feature allows the process to exit gracefully after completing all pending asynchronous operations. The code sample demonstrates how to use the exit package to delay the process exit until after a timeout, ensuring that any operations within the timeout are completed.
const exit = require('exit');
// Perform some asynchronous operations
setTimeout(() => {
console.log('Exiting...');
exit(0); // Exit with status code 0
}, 1000);
While primarily focused on providing replacements for the fs module to make it behave more gracefully, this package also handles process exiting more smoothly under certain file system conditions. It does not directly compare with 'exit' in terms of functionality but offers a broader scope of graceful operations.
A replacement for process.exit that ensures stdio are fully drained before exiting.
To make a long story short, if process.exit
is called on Windows, script output is often truncated when pipe-redirecting stdout
or stderr
. This module attempts to work around this issue by waiting until those streams have been completely drained before actually calling process.exit
.
See Node.js issue #3584 for further reference.
Tested in OS X 10.8, Windows 7 on Node.js 0.8.25 and 0.10.18.
Based on some code by @vladikoff.
Install the module with: npm install exit
var exit = require('exit');
// These lines should appear in the output, EVEN ON WINDOWS.
console.log("omg");
console.error("yay");
// process.exit(5);
exit(5);
// These lines shouldn't appear in the output.
console.log("wtf");
console.error("bro");
In Windows, clone the repo and cd to the test\fixtures
directory. The only difference between log.js and log-broken.js is that the former uses exit
while the latter calls process.exit
directly.
This test was done using cmd.exe, but you can see the same results using | grep "std"
in either PowerShell or git-bash.
C:\node-exit\test\fixtures>node log.js 0 10 stdout stderr 2>&1 | find "std"
stdout 0
stderr 0
stdout 1
stderr 1
stdout 2
stderr 2
stdout 3
stderr 3
stdout 4
stderr 4
stdout 5
stderr 5
stdout 6
stderr 6
stdout 7
stderr 7
stdout 8
stderr 8
stdout 9
stderr 9
C:\node-exit\test\fixtures>node log-broken.js 0 10 stdout stderr 2>&1 | find "std"
C:\node-exit\test\fixtures>
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
2013-11-26 - v0.1.2 - Fixed a bug with hanging processes.
2013-09-26 - v0.1.1 - Fixed some bugs. It seems to actually work now!
2013-09-20 - v0.1.0 - Initial release.
Copyright (c) 2013 "Cowboy" Ben Alman
Licensed under the MIT license.
FAQs
A replacement for process.exit that ensures stdio are fully drained before exiting.
The npm package exit receives a total of 18,568,952 weekly downloads. As such, exit popularity was classified as popular.
We found that exit 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.
Product
Module Reachability filters out unreachable CVEs so you can focus on vulnerabilities that actually matter to your application.
Company News
Socket is bringing best-in-class reachability analysis into the platform — cutting false positives, accelerating triage, and cementing our place as the leader in software supply chain security.
Product
Socket is introducing a new way to organize repositories and apply repository-specific security policies.