SlideShare a Scribd company logo
Ramanujan College, University of Delhi
New Delhi-110019, India.
Topic: Full Stack Web Development-2
Introduction
• Learning about the Internals of Node.js
• Describes the inner workings of Node.js
• Its principles, and basic ideas
Introduction
Introduction
• Node.js was first released in 2009 by Ryan Dahl as a reaction to how slow web
servers were at the time
• Most web servers would block for any I/O task, such as reading from the file
system or accessing the network, and this would dramatically lower their
throughput.
• Node.js changed this model by making all I/O tasks non-blocking and
asynchronous. This allowed web servers written in Node.js to serve thousands of
requests concurrently.
Introduction
Introduction
• Illustrates the threaded model processing two requests, GetFile and
GetData.
• The GetFile request first opens the file, reads the contents, and then
sends the data back in a response.
• All this occurs in order on the same thread.
• The GetData request connects to the DB, queries the necessary data,
and then sends the data in the response.
Introduction
The Node.js event model does things differently.
• Instead of executing all the work for each request on individual threads,
• work is added to an event queue and then picked up by a single thread running
an event loop.
• The event loop grabs the top item in the event queue, executes it, and then
grabs the next item.
• When executing code that is no longer live or has blocking I/O, instead of
calling the function directly, the function is added to the event queue along
with a callback that is executed after the function completes.
• When all events on the Node.js event queue have been executed, the Node
application terminates.
Introduction
Introduction
• illustrates the way Node.js handles the GetFile and GetData requests.
• The GetFile and GetData requests are added to the event queue.
• Node.js first picks up the GetFile request, executes it, and then completes by
adding the Open() callback function to the event queue.
• Next, it picks up the GetData request, executes it, and completes by adding
the Connect() callback function to the event queue.
• This continues until there are no callback functions to be executed.
• Notice that the events for each thread do not necessarily follow a direct
interleaved order.
• For example, the Connect request takes longer to complete than the Read
request, so Send(file) is called before Query(db).
Blocking I/O in Node.js
• Blocking I/O stops the execution of the current thread and waits for a
response before continuing.
• Some examples of blocking I/O are
• Reading a file
• Querying a database
• Socket request
• Accessing a remote service
• Therefore, any requests that perform blocking I/O are performed on a different thread in
the background. Node.js implements a thread pool in the background. When an event that
requires blocking I/O is retrieved from the event queue, Node.js retrieves a thread from the
thread pool and executes the function there instead of on the main event loop thread. This
prevents the blocking I/O from holding up the rest of the events in the event queue
Introduction
Introduction
•In the Node.js event model,
•work is added as a function with a callback to the
event queue,
•and then picked up on the event loop thread.
• The function is then executed on the event loop
thread in the case of non-blocking, or on a separate
thread in the case of blocking
Introduction
Internal composition of Node.js
Libuv
Libuv
Libuv
Composition of Node.js
EventLoop

More Related Content

PPTX
Events for JavaScript event loop track.pptx
PPTX
NodeJS - Server Side JS
PPTX
What is Node.js
PDF
Introduction to Node JS.pdf
PDF
Basic Understanding and Implement of Node.js
PDF
NodeJS ecosystem
PPT
Threads in java
PDF
Node js internal
Events for JavaScript event loop track.pptx
NodeJS - Server Side JS
What is Node.js
Introduction to Node JS.pdf
Basic Understanding and Implement of Node.js
NodeJS ecosystem
Threads in java
Node js internal

Similar to Node js for backend server development. (20)

PPTX
Node.js: A Guided Tour
PPTX
Scheduling Thread
PPT
Parallel programming
PDF
Understanding the Single Thread Event Loop
PPTX
Kalp Corporate Node JS Perfect Guide
PDF
Servlet and JSP
ODP
Multithreading 101
PPTX
Introduction to Node.JS
PPTX
Event Handling -_GET _ POSTimplementation.pptx
PDF
WTF is Twisted?
PPTX
Object-Oriented-Prog_MultiThreading.pptx
PDF
Android volley
PPT
Hybernat and structs, spring classes in mumbai
DOCX
node.js interview questions and answers.
PDF
Tech io nodejs_20130531_v0.6
PDF
Ruby's Concurrency Management: Now and Future
PDF
Introduction to Node.js: What, why and how?
PDF
OHHttpStubs
PPTX
Concurrency Programming in Java - 05 - Processes and Threads, Thread Objects,...
PPTX
JAVA SERVLETS acts as a middle layer between a request coming from a web brow...
Node.js: A Guided Tour
Scheduling Thread
Parallel programming
Understanding the Single Thread Event Loop
Kalp Corporate Node JS Perfect Guide
Servlet and JSP
Multithreading 101
Introduction to Node.JS
Event Handling -_GET _ POSTimplementation.pptx
WTF is Twisted?
Object-Oriented-Prog_MultiThreading.pptx
Android volley
Hybernat and structs, spring classes in mumbai
node.js interview questions and answers.
Tech io nodejs_20130531_v0.6
Ruby's Concurrency Management: Now and Future
Introduction to Node.js: What, why and how?
OHHttpStubs
Concurrency Programming in Java - 05 - Processes and Threads, Thread Objects,...
JAVA SERVLETS acts as a middle layer between a request coming from a web brow...
Ad

Recently uploaded (20)

PDF
medical staffing services at VALiNTRY
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Digital Strategies for Manufacturing Companies
PPTX
ISO 45001 Occupational Health and Safety Management System
PPTX
ai tools demonstartion for schools and inter college
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
System and Network Administration Chapter 2
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Complete React Javascript Course Syllabus.pdf
PPTX
Essential Infomation Tech presentation.pptx
PDF
System and Network Administraation Chapter 3
PDF
AI in Product Development-omnex systems
PPTX
L1 - Introduction to python Backend.pptx
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPT
Introduction Database Management System for Course Database
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
medical staffing services at VALiNTRY
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Digital Strategies for Manufacturing Companies
ISO 45001 Occupational Health and Safety Management System
ai tools demonstartion for schools and inter college
VVF-Customer-Presentation2025-Ver1.9.pptx
System and Network Administration Chapter 2
Design an Analysis of Algorithms I-SECS-1021-03
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Which alternative to Crystal Reports is best for small or large businesses.pdf
Complete React Javascript Course Syllabus.pdf
Essential Infomation Tech presentation.pptx
System and Network Administraation Chapter 3
AI in Product Development-omnex systems
L1 - Introduction to python Backend.pptx
How to Choose the Right IT Partner for Your Business in Malaysia
Introduction Database Management System for Course Database
How Creative Agencies Leverage Project Management Software.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Ad

Node js for backend server development.

  • 1. Ramanujan College, University of Delhi New Delhi-110019, India. Topic: Full Stack Web Development-2
  • 2. Introduction • Learning about the Internals of Node.js • Describes the inner workings of Node.js • Its principles, and basic ideas
  • 4. Introduction • Node.js was first released in 2009 by Ryan Dahl as a reaction to how slow web servers were at the time • Most web servers would block for any I/O task, such as reading from the file system or accessing the network, and this would dramatically lower their throughput. • Node.js changed this model by making all I/O tasks non-blocking and asynchronous. This allowed web servers written in Node.js to serve thousands of requests concurrently.
  • 6. Introduction • Illustrates the threaded model processing two requests, GetFile and GetData. • The GetFile request first opens the file, reads the contents, and then sends the data back in a response. • All this occurs in order on the same thread. • The GetData request connects to the DB, queries the necessary data, and then sends the data in the response.
  • 7. Introduction The Node.js event model does things differently. • Instead of executing all the work for each request on individual threads, • work is added to an event queue and then picked up by a single thread running an event loop. • The event loop grabs the top item in the event queue, executes it, and then grabs the next item. • When executing code that is no longer live or has blocking I/O, instead of calling the function directly, the function is added to the event queue along with a callback that is executed after the function completes. • When all events on the Node.js event queue have been executed, the Node application terminates.
  • 9. Introduction • illustrates the way Node.js handles the GetFile and GetData requests. • The GetFile and GetData requests are added to the event queue. • Node.js first picks up the GetFile request, executes it, and then completes by adding the Open() callback function to the event queue. • Next, it picks up the GetData request, executes it, and completes by adding the Connect() callback function to the event queue. • This continues until there are no callback functions to be executed. • Notice that the events for each thread do not necessarily follow a direct interleaved order. • For example, the Connect request takes longer to complete than the Read request, so Send(file) is called before Query(db).
  • 10. Blocking I/O in Node.js • Blocking I/O stops the execution of the current thread and waits for a response before continuing. • Some examples of blocking I/O are • Reading a file • Querying a database • Socket request • Accessing a remote service • Therefore, any requests that perform blocking I/O are performed on a different thread in the background. Node.js implements a thread pool in the background. When an event that requires blocking I/O is retrieved from the event queue, Node.js retrieves a thread from the thread pool and executes the function there instead of on the main event loop thread. This prevents the blocking I/O from holding up the rest of the events in the event queue
  • 12. Introduction •In the Node.js event model, •work is added as a function with a callback to the event queue, •and then picked up on the event loop thread. • The function is then executed on the event loop thread in the case of non-blocking, or on a separate thread in the case of blocking
  • 15. Libuv
  • 16. Libuv
  • 17. Libuv