Search⌘ K

Process

Explore how to manage Node.js processes by accessing their unique Process ID and handling their lifecycle events. Learn to work with standard input and output streams to interact with users through the terminal, including reading user input and writing output. This lesson helps you understand how to control and retrieve information about running Node.js scripts using the global process object.

Process ID (pid)

It is important to understand that when you run a script, it is treated as its own process. You may have many processes running simultaneously on your machine, and each has its own unique identification called a Process ID (pid). You will learn how you can pass over responsibility to a separate process later on but, for now, here is how you can output the Process ID.

console.log(`This process is pid ${process.pid}`);

What about adding a callback when the current process has ended? When the script exits, this will fire.

process.on('exit', (code) => {
  console.log(`The process has
...