NodeJS Introduction
§ In this tutorial we will discuss NodeJS will help
you learn the essentials of Node.js starting from the basics to an advanced
level.
Prerequisites
§ Before proceeding with this tutorial, you should
have a Basic knowledge of HTML, JavaScript and web application is recommended.
WEB APPLICATION REQUIREMENTS :ü Browser software.ü Technology to develop client side.
ü Technology to develop server side.
ü User software.
ü Database software.
WEB Server Software :
§ Web server software is special piece of s/w (or)
special s/w which can manages the web applications and web resources we
executes this web resources automatically or dynamically whenever your requesting
.
Responsibilities of web server :§ It accepts all client http requests.
§ After accepting the request it passes your request
to appropriate web resources of web application.
§ Web server proceeds your request and produce result.
§ Finally it will Gives resultant out put back to the
client.
What is NodeJS?
§ NodeJS
is the Server side scripting language.
§ By
using NodeJS, we can develop Http Servers.
§ We
can develop Node application by using JavaScript.
§ Node
follows Event Driven Model.
§ Node
supports the modules. Predefined modules & custom modules.
Features
of NodeJS§ NodeJS uses an event driven programming
paradigm.
§ Event
driving paradigm means that if we do any work, we need to raise an event for
that work.
§ In
this type of, flow of execution is determined by the events like user clicks or
other programming threads or query result from database.
§ Events
are handled by event handlers or event callbacks.
§ Event
callback is nothing it is a function that is invoked when something significant
happens like when click event is performed by user or the result of database
query is available.
§ Non-blocking I/O model§ When
we send a request to the server and have to fetch some data, what we do is
first our request goes to the server, and then the server sends the request
database, searches its expected results and then gives it back to you again.
§ When
the second request comes, the server accepts it, processes it and then gives a
response. During this time, if two to three requests come at the same time,
first it checks request on the priority basis that the request which come first
that request serves first until first request has not been completed till
second request has to wait.ie. The request will remain pending in queue. Once
first request gives the result then second request process.
§ When
we are sending a request in php/java/.net technology to the server Remaining
request is blocked until the first request gets the result (second, third).
This request remains blocked until the result of the first request is not gets.
What happened
when you send a request in NodeJS
§ Whenever
we send a request in NodeJS. NodeJS listen the first request and after listing
the first request NodeJS becomes ready to listing another request at the same
time i.e. NodeJS does not wait for I/O
completion of the first request.
§ A
NodeJS uses non-blocking I/O operations. This allows a single process to serve
multiple requests at the same time. Instead of process being blocked and
waiting for single I/O operation to complete, this waiting time is used to
serve other requests. All Node.js libraries and the Node core api offer
non-blocking operations with few minor exceptions.
What difference between NodeJs and other server
side web technology just
like(Java/PHP/.Net)
Java
|PHP |.Net
§ Browser
Sends request to server.
§ Server
sends request to database or file.
§ While
the database or file is being read/written, the server simply waits until the
operation is completed.
§ After
completion of database/file operation, the content is sent to the browser.
§ The
server is ready to receive next request.
NodeJS
§ Browser
Sends request to server.
§ Server
sends request to database or file.
§ Server
will not wait until the completion of database operation/file operation
simply it receives another request
starts its processing.
§ After
completion of database/file operation, the content is sent to the browser.