Working of Node js :an overview
Basically, the internal structure of Node js consists of a v8 engine and libUV .The v8 engine is based on c to compile js and libUV comes with an event loop and thread pool.
Now, when we write the command node <filename.js>,
the first thing that takes place is a node process gets created. The node process consists of the main thread.On this main thread itself the node js process runs.
The first step in this process is to initialize the project.
After the initialization of process is complete, the top level code gets executed.
The top level code is the one that exists without any callbacks.Then it requires all the packages and modules and registers the event callbacks.
Finally , it starts the event loop process.
All these steps occur in the main thread, we also have a thread pool which comes into play when we have a CPU intensive task in the main thread.
The CPU intensive tasks include tasks related to encryption/decryption,compression of files etc. In case of these situations , the even loop offloads the CPU intensive tasks to the thread pool.