Skip to main content

NodeJs Working Mechanism

Nodejs is an environment built with Google's V8 engine to run javascript code outside of the browser (i.e in the server side). It is single threaded unlike other server side technologies like Java and PHP. They open new threads for each request; but with Nodejs all of this happens on a single thread with even shared resources.  All of the operations that a developer does on a server built with Nodejs happen asynchronously and that means it does not take a specific amount of time. So, to work this method we use something called callbacks; which are anonymous functions that we pass to a function so that it will be executed once the first function finishes executing.
┌───────────────────────┐
┌─>│ timers │
│ └──────────┬────────────┘
│ ┌──────────┴────────────┐
│ │ I/O callbacks │
│ └──────────┬────────────┘
│ ┌──────────┴────────────┐
│ │ idle, prepare │
│ └──────────┬────────────┘ ┌───────────────┐
│ ┌──────────┴────────────┐ │ incoming: │
│ │ poll │<─────┤ connections, │
│ └──────────┬────────────┘ │ data, etc. │
│ ┌──────────┴────────────┐ └───────────────┘
│ │ check │
│ └──────────┬────────────┘
│ ┌──────────┴────────────┐
└──┤ close callbacks │
└───────────────────────┘


Comments