Unless otherwise noted, functions are all asynchronous and do not block execution\.
.sp
.SS"Helpers and Global Variables"
.SS"Helpers"
These objects are available to all programs\.
.PP
node\.exit(code)
.RS4
Immediately ends the process with the specified code\.
.RE
.PP
node\.cwd()
.RS4
Returns the current working directory of the process\.
.RE
.PP
ARGV
__filename
.RS4
An array containing the command line arguments\.
The filename of the script being executed\.
.RE
.SS"The process Object"
process is the equivalent of window in browser\-side javascript\. It is the global scope\. process is an instance of node\.EventEmitter\.
.sp
.TS
allbox tab(:);
ltB ltB ltBx.
T{
Event
T}:T{
Parameters
T}:T{
Notes
T}
.T&
lt lt lt.
T{
"exit"
.sp
T}:T{
code
.sp
T}:T{
Made when the process exits\. A listener on this event should not try to perform I/O since the process will forcibly exit in less than microsecond\. However, it is a good hook to perform constant time checks of the module\(cqs state (like for unit tests)\. The parameter code is the integer exit code passed to process\.exit()\.
.sp
T}
.TE
.PP
ENV
process\.exit(code=0)
.RS4
An object containing the user environment\. See environ(7)\.
Ends the process with the specified code\. By default it exits with the success code 0\.
.RE
.PP
__filename
process\.ARGV
.RS4
The filename of the script being executed\.
An array containing the command line arguments\.
.RE
.PP
process
process\.ENV
.RS4
A special global object\. The
process
object is like the
window
object of browser\-side javascript\.
An object containing the user environment\. See environ(7)\.
.RE
.SS"Utilities"
These function are in "/utils\.js"\. Use require("/utils\.js") to access them\.
@ -418,36 +435,6 @@ Node comes with several libraries which are installed when "make install" is run
.sp
(Functions require_async() and include_async() also exist\.)
.sp
.sp
.it1an-trap
.nran-no-space-flag1
.nran-break-flag1
.br
process.addListener("exit", function () { })
.RS
When the program exits a special object called process will emit an "exit" event\.
.sp
The "exit" event cannot perform I/O since the process is going to forcibly exit in less than microsecond\. However, it is a good hook to perform constant time checks of the module\(cqs state\. E\.G\. for unit tests:
.sp
.sp
.RS4
.nf
include("asserts\.js");
var timer_executed = false;
setTimeout(function () {
timer_executed = true
}, 1000);
process\.addListener("exit", function () {
assertTrue(timer_executed);
});
.fi
.RE
Just to reiterate: the "exit" event, is not the place to close files or shutdown servers\. The process will exit before they get performed\.