Working of Node JS
- Node JS works on single thread
- So suppose you run a loop for like 100 million times, so single thread of node has to perform that which makes it processor intensive which is not a area where Node JS shines.
- Node JS Works asynchronously and it is non blocking
- As we know Node JS is single threaded so it does not wait for an I/O or network to return a response, instead it creates a callback which handles the response. When the response is received.
Node is good at following work :
- After making an api call, it does not wait for the response of that API, instead it writes a call back which handles the event of getting data from API and puts it list of events that it has to execute one by one.
- Waits for a event to happen and executes the event
- When lots of data has to be handled but not processed (Lots of API call to be made)
- I/O intensive
- Waiting for lots of Input and Output devices together
Node is not good for follow work :
- Data Calculation of large amount
- Processor Intensive
- Blocking Operations
Example Applications :
- Because of event driven model
- APIs fronting NO SQL DB
- Command Line utilities
- Build Tooling (Like building angular application)