Process
Learn how to use standard input and standard output, using the global object process.
We'll cover the following
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 now finished, exiting with code: ${code}`);
});
Get hands-on with 1400+ tech skills courses.