node. JS is a commonly used JavaScript runtime environment, this article and everyone sharing is mainly node. js in the common properties and methods of the process module, I hope that through the sharing of this article, we learn about node. JS http://www.maiziedu.com/ course/694/helpful.
If you are not dealing with command-line tools, there may be few opportunities for us to use some of the methods or properties in the process module. However, if you want to do a more complex build tool like Webpack or gulp, because the Bash interface is a tool that communicates directly with the user, a friendly input and output, complete hints are all very necessary.
Attribute name Purpose
Platform: Judging the current system platform
ARGV: Array of command-line arguments for the current process
Execpath: The absolute path of the executable file for the current process
STDOUT: point to standard output
STDIN: point to standard input
STDERR: pointing to standard error
STDERR: pointing to standard error
We can use this directly in our code.
Console.log (Porcess.platform)//Darwin
Using argv will return an array of command lines, and we can get the user-specific commands through an array.
Console.log (PROCESS.ARGV); ['/usr/local/bin/node ', '/users/ali-130257n/www/weex-jackzoo/projects/demo.js ', '-p ', '-V ']
In general, we would like to get some final parameters, the first two not required, we can
Let args = Process.argv.slice (2);
Console.log (args)
['-P ', '-V ']
There are many ways that process provides. Roughly what we can use is some of the following.
CWD: Returns the path to the working directory where the current script is running
Abort: End the process immediately
Nexttick: Specifies the task to run first for the next event loop
Some events supported by process, we can do some friendly hints or deal with some events.
Uncaughtexception: The Uncaughtexception event is triggered when the current process throws an unexpected error that is not caught
Message: Accept messages from the parent process
Rejectionhandled: Used to capture the promise error handling associated with it and the resulting reject
Unhandledrejection: The same is the case for capturing reject with no associated promise error handling
Const Unhandledrejections = new Map ();
Process.on (' unhandledrejection ', (reason, p) + = {
Unhandledrejections.set (p, reason);
});
Process.on (' rejectionhandled ', (p) + = {
Unhandledrejections.delete (P);
});
Warning: The current process starts when a warning is generated
Process.on (' Warning ', (warning) + = {
Console.warn (Warning.name); Print The warning name
Console.warn (Warning.message); Print the warning message
Console.warn (Warning.stack); Print the Stack trace
});
node. JS process module Common Properties and methods