- JavaScript standard Reference Tutorial (Alpha)
- Draft II: node. js
- Process Object
Process Object
From the JavaScript standard reference tutorial (Alpha), by Ruan Feng
Directory
processObject is a global object of node that provides information about the current node process. It can be used anywhere in the script without having to load it through a require command. The object deploys an EventEmitter interface.
Exit code for the process
When the process exits, an integer value is returned, indicating the state at exit. This integer value is called the exit code. The following is a common node process exit code.
- 0, Normal exit
- 1, an uncaught error occurred
- 5,V8 Execution Error
- 8, incorrect parameters
- 128 + signal value, if node receives an exit signal (such as Sigkill or Sighup), its exit code is 128 plus the signal value. Since the binary form of 128 is 10000000, the latter seven bits of the exit code are the signal values.
Bash can use environment variables $? to get the exit code for the previous operation.
$ node nonexist.jsError: Cannot find ‘nonexist.js‘$ echo $?1
In the above code, node executes a script file that does not exist, the result is error, the exit code is 1.
Property
The Process object provides a series of properties for returning system information.
- PROCESS.ARGV: Returns an array of command-line arguments for the current process.
- Process.env: Returns an object that is a member of the current shell's environment variables, such as
process.env.HOME .
- Process.installPrefix:node the installation path prefix, for example
/usr/local , node's execution file directory is /usr/local/bin/node .
- Process.pid: The process number of the current process.
- Process.platform: Current system platforms, such as Linux.
- Process.title: The default value is "Node", which you can customize.
- Process.version:Node versions, such as v0.10.18.
The following is an introduction to the main properties.
Stdout,stdin,stderr
The following properties point to System I/O.
(1) StdOut
The StdOut property points to standard output (file descriptor 1). Its write method is equivalent to Console.log, which can be used to display content to the user in standard output.
console.log = function(d) { process.stdout.write(d + ‘\n‘
Nodejs-process Object