Properties of Process Object in NodeJS

Introduction

This article explains the properties of Process objects. On the next loop of an event loop, call this callback. We know that every node application runs on a single thread, in other words you can write any code to be run on a single thread. Having multiple lines of execution is done by the operating system by processing interrupts, saving the state of the current thread and starting another one.

Process.nextTick() function

The Process.nextTick() function typically runs before any other I/O events fire. As we know, every node application runs on a single thread, in other words only one task or event is processed by Node's event loop. In an event loop, a queue of callbacks are processed by Node on every Tick of the event loop. On the next loop around the event loop calls these callbacks.

The Process.nextTick() function defers the function untill a completely new stack. You can call as many functions as you want to in the current stack. When the event loop is looking for a new event to execute the nextTick function will be in the queue and will execute an entire new stack. The Process.nextTick() function defers the execution of an action until the next pass around the event loop. I have given an example below of how the function is invoked in the process.nextTick. Let's see.

Write the code in the Notepad editor and save it as demo.js.

nextTick

Now open the Node.js Command prompt to execute the node as in the following figure:

nodejs 

NextCMD

If you run the code above then you will see that "LastName" will be printed on your console before "FirstName" as we have delayed the invocation of FirstName() until the nextTick of  the event.

Process.MemoryUsage()

To determine the efficiency of your application you can use "process.memoryusage". The following sample code gets the Resident Set Size (RSS) heaptotal and heapUsed memory used  in the process. Resident Set Size (RSS) is the portion of process  memory that is held in RAM.

memory

memoryuse

Returns an object memory usage of the Node process representd in bytes.

Process.cwd() and Process.Arch

The Current Working Directory (CWD) is the current process's directory and the "process.arch" provides the processor architecture you are running in, for example "x64", "ia32", "arm".

cwdarch

cmdCwdArc

x64 indicaters a 64-bit processor or the 64-bit version of Windows.

Summary

This article showed the properties of the Process object and how it works in a Console Application.

Up Next
    Ebook Download
    View all
    Learn
    View all