Course:
Full Stack Web
Development
Nimra Idrees
Topic: Node.js
Introduction
Node.js is an open-source,
cross-platform JavaScript Ryan Dahl developed it in 2009,
Developers use Node.js to
runtime environment and and its latest iteration, version
create server-side web
library for running web 15.14, was released in April
applications
applications outside the client's 2021.
browser.
Perfect for data-intensive Node.js is a runtime Built on the V8 JavaScript
applications since it uses an environment that allows engine from Chrome, which
asynchronous, event-driven JavaScript to be executed on compiles JavaScript into
model. the server side. efficient machine code.
12/4/2024 By Nimra Idrees 3
Node.js operates on a single-threaded event-driven architecture, utilizing
an event loop to handle multiple concurrent operations without blocking.
When a client sends a request to a Node.js server, the request is added to
an event queue.
The event loop continuously checks this queue and processes each
request.
Working
If a request involves an I/O operation, Node.js offloads it to the system
kernel, which handles it asynchronously.
Once the I/O operation is complete, the kernel notifies Node.js, executing
the corresponding callback function.
This non-blocking I/O and event-driven model allows Node.js to handle
many simultaneous connections efficiently, making it ideal for building
scalable, high-performance network applications.
12/4/2024 By Nimra Idrees 4
Execution Time Is Very Fast And It Runs Very
Quickly.
More than 50,000 bundles available in the
Node Package Manager
Why do we NodeJs do not need to wait for an API to
use Node.js return data
Loading time for an audio or video is
reduced by NodeJs
NodeJs is open-source and it is nothing but
a JavaScript framework
12/4/2024 By Nimra Idrees 5
Features of NodeJs
Architecture / Design – what is the difference
Asynchronous in Nature and Event driven
Single Threaded Architecture Scalable
Quick Execution Time for Code Compatibility on the Cross Platforms
No Buffering Uses JavaScript
Fast Data Streaming
12/4/2024 By Nimra Idrees 6
Is Node.js a Programming Language?
• Node.js is not a programming language; it is a runtime environment allowing you to execute
JavaScript code on the server side, outside a web browser. Built on the V8 JavaScript engine
from Chrome, Node.js compiles JavaScript into machine code for efficient execution. It extends
JavaScript capabilities by providing additional features and libraries for server-side
development, such as file system access, network communication, and asynchronous I/O
operations.
• While JavaScript is the programming language used with Node.js, the runtime environment
provides the tools and frameworks to build scalable and high-performance server applications.
Node.js’s non-blocking, event-driven architecture makes it ideal for real-time applications, web
servers, APIs, and more. In summary, Node.js is a robust environment that leverages
JavaScript to enable server-side programming, but it is not a programming language.
12/4/2024 By Nimra Idrees 7
Node.js Architecture
12/4/2024 By Nimra Idrees 8
Parts of Node.js
12/4/2024 By Nimra Idrees 9
Modules
• Modules are like JavaScript libraries that
can be used in a Node.js application to
include a set of functions.
• In order to include a module in a Node.js
application, use the require() function
with the parenthesis containing the
name of the module.
12/4/2024 By Nimra Idrees 10
Modules
12/4/2024 By Nimra Idrees 11
Console
• The console is a module that provides a
method for debugging that is similar to
the basic JavaScript console provided by
internet browsers. It prints messages to
stdout and stderr.
12/4/2024 By Nimra Idrees 12
Cluster
• Node.js is built-on on the
concept of single-threaded
programming. Cluster is a
module that allows multi-
threading by creating child
processes that share the
same server port and run
simultaneously.
12/4/2024 By Nimra Idrees 13
Global
Global objects in
Node.js are available
in all modules.
These objects are
functions, modules,
strings, etc.
12/4/2024 By Nimra Idrees 14
Error Handling
12/4/2024 By Nimra Idrees 15
Error Handling
• Errors in Node.js are handled through
exceptions. For example, let's handle the
error that would occur when we divide a
number by zero. This error would crash
the Node.js application, so we should
handle this error to continue with the
normal execution of the application.
12/4/2024 By Nimra Idrees 16
Readable: These are the types of streams
from which data can be read
Writable: These are the types of streams
to which data can be written
Streaming
Duplex: These are both readable and
writable streams
Transform: Streams that can manipulate
the data while it is being read or written
12/4/2024 By Nimra Idrees 17
Domain
External Binding:
Internal Binding: Error
Error emitter is
emitter executes its
explicitly added to a
code inside the run
domain via its add
method
method
12/4/2024 By Nimra Idrees 18
Buffer & DNS
Buffer is a module that allows the handling
of streams that contain only binary data. An
empty buffer of length '10' can be created by
this method:
DNS module is used to connect to a DNS
server and perform name resolution by
using the following method:
DNS module is also used for performing
name resolution without a network
communication by using the following
method:
12/4/2024 By Nimra Idrees 19
Debugger
• Node.js includes a debugging utility that can be accessed by a
built-in debugging client.
• Node.js debugger is not feature-packed but supports the simple
inspection of code.
• The debugger can be used in the terminal by using the 'inspect'
keyword before the name of the JavaScript file.
• In order to inspect a file—myscript.js, for example—you can follow
this method:
12/4/2024 By Nimra Idrees 20
Real-Time APIs and
Web Servers
Applications Microservices
Applications of Single-Page
Streaming Command-
Node.js Applications
Applications Line Tools
(SPAs)
Internet of
Things (IoT)
12/4/2024 By Nimra Idrees 21
Node.js Use Cases
12/4/2024 By Nimra Idrees 22
!شکریہ
Thankyou