Nodejs-process Object

Source: Internet
Author: User

    • JavaScript standard Reference Tutorial (Alpha)
    • Draft II: node. js
    • Process Object
    • GitHub
    • TOP
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.