Node.js


 Q - what is Node.js? 

Node.js is Open source, cross platform .

Node.js is a tool/software that lets us run javascript on the server .

In not so simple word Node.js is a high performance network application and frame work.

Node's goal is to provide an easy way to build scalable network program. 

javascript only runs in the browser like chrome, firefox.. with Node.js, we can run it on the backend(server side)too. and Node.js runs on V8.

Node.js is use frontend for React.js, Angular, Vue.js.

Q - where Node.js is used?
  • Building APIs(React & GraphQL)
  • Real time apps like chat apps, live updates, notification.
  • Streaming Apps like youtube, netflix, spotify.
  • IoT Application
  • server side rendering for web page
=> Features of Node.js:

1. Fast: Runs on Google chrome's V8 Engine (very quickly).

2. Non-Blocking: can handle many users at the same time common apps runs(like chat apps). 

3. One Language: you can use java script for both frontend and backend.

4. NPM(Node package manager): give Access to thousands of free libraries/tools.

5. Event Based: works on event like request comes -> give response.

6. Cross platform: work on windows, mac, linux.

7. Scalability: can easily handle small apps and large scale enterprise apps.

8. Real time Apps: Best for application that need real time updates like whatsApp, stock market apps, etc.


1.Incoming Requests (Users):
  • Many users send requests (like opening a page, logging in, uploading a file).
  • These requests go into a queue.
2.Event Queue: 
  • All requests are stored in the Event Queue.
  • Example: If 100 users click “Login” at the same time, all 100 requests will wait here.
3.Event Loop:
  • The Event Loop continuously checks the Event Queue.
  • It picks requests one by one and decides:
  • If request is simple (like reading data, sending response) → handle immediately.
  • If request is heavy/complex (like file processing, database query) → send to worker threads.
4.Worker Thread Pool:
  • A group of background workers that handle heavy tasks (like image processing, database operations, file reading).
  • Once done, they send the result back to the Event Loop → then user gets a response.


Comments

Popular Posts