“process” is one of the most important global properties in the Node.js process. The process contains information on the context that Node.js is running your script or application in. Now, let’s get into detail; we’ll be discussing what process is and important properties plus methods.
What Is Process?
Important Process Properties
The “process” object contains these helpful properties: stdin, stdout, stderr, env, arch, and argv. It also has these helpful methods: chdir, cwd, exit, and kill. Lastly, “process” is an instance of the EventEmitter class, giving it helpful events the developer can listen to. However, we will only be discussing the properties and methods; let’s start with the properties.
The properties stdin, stdout, and stderr control input, output, and error output in the Node.js process respectively. Each one is a stream that can be manipulated by the developer. The arch property tells you what the processor architecture is. The argv property lists the command line arguments passed to the Node.js process. Finally, env lists the environment properties associated with the current process such as shell, user, path, editor, and more. Now, with properties done, let’s talk methods.
The important methods to know are chdir, cwd, exit, and kill. The chdir method changes the current directory; cwd displays the current working directory. The exit method exits the process, stopping the program. Finally, the kill method can kill any running process given a pid (process id), which can be obtained using another method outside the scope of this post.
Now, with that said, I hope this post along with all the other Node.js posts were helpful to you in learning the basic modules in Node.js. This is the end of Node.js basic. I enjoyed learning the modules over the course of the week and I hope you did too!
For More Information: