Node js tutorial - What is node js - learn node js




Related nodejs article tags - node js - node js tutorial - node js examples

What is NodeJS :

  • Node.js lets us use JavaScript language on the server… so it allows us to write JavaScript outside the browser!
  • Node.js has all the power of JavaScript and offers us a whole new way of developing dynamic websites.
learn nodejs - nodejs tutorial - nodejs benefits - nodejs example programs
    • Asynchronous Event Driven Server Side JavaScript
    • Non-blocking I/O and File API
    • Runs on Google JS V8 Engine
    • Single Threaded
    • Highly Scalable
    • Node Apps are created using JavaScript
    • Faster in performance
learn nodejs - nodejs tutorial - nodejs multi threaded server - nodejs example programs
learn nodejs - nodejs tutorial - nodejs server workflow - nodejs example programs
  • 1.Multiple requests are sent to the Node.js server.
  • 2.The event-driven nature of Node.js creates a loop of events for all requests and handles them under a single thread.
  • 3.These events are then delegated to the appropriate non-blocking event handler.
  • 4.The response received travels the reverse way to the requested end point.
  • 5.Since the process happens under a single thread, the response is sent asynchronously without causing page refresh.
Related nodejs article tags - node js - node js tutorial - node js examples

Explain NodeJS :

  • An open-source runtime environment that contains JavaScript code for execution in the server to aid in asynchronous request-response strategy.
  • A library with variety of modules needed for network and web application development.
  • Is developed by Ryan Dahl in 2009.
  • Is part of V8 JavaScript, a Google's implementation for the Chrome browser, with "Just in Time" compilation services to achieve high speeds for executions.
  • Uses a non-blocking, event-driven I/O environment to handle high-critical real-time applications running across distributed devices.
  • Prevents its applications from data buffers, regardless of its extended service processing tasks
Related nodejs article tags - node js - node js tutorial - node js examples

History of NodeJS :

learn nodejs - nodejs tutorial - nodejs example programs

learn nodejs - nodejs tutorial - nodejs example programs

How webpage works :

learn nodejs - nodejs tutorial - How webpage works - nodejs example programs

How webpage works

how nodejs works :

  • Node.js offers a server-side environment, which allows us to also use JavaScript language to generate web pages. Basically, it replaces server languages such as PHP, Java EE, etc.
learn nodejs - nodejs tutorial - What is nodejs - nodejs example programs

learn nodejs - nodejs tutorial - What is nodejs - nodejs example programs

Blocking model vs. non-blocking model :

learn node js - node js tutorial - node js non blocking io - node js advantages -  node js programs
  • Considering a program, which upload a file and then display it. Below is the code written in a blocking model:
    • Upload the file
    • Display the file
    • Do something else
  • The actions are carried out in top to bottom order.
    • The program will upload a file to the Internet.
    • The program will display the file to the user.
    • Then, the program can do other things (i.e. carry out other actions).
  • Lets see the same code in a non-blocking model:
    • Upload a file
    • As soon as it’s finished, display the file
    • Do something else
  • The program wont carry out the tasks in the order that they are written. It does this:
    • The program launches the upload of the file to the internet.
    • The program does other things (the program follows its course).
    • As soon as the upload is finished, the program carries out the actions that we asked it to do: it displays the file.

On the whole, the running of the program can therefore be represented as in the next figure.

learn nodejs - nodejs tutorial - non blocking mode of nodejs - nodejs example programs

learn nodejs - nodejs tutorial - Non blocking mode of nodejs - nodejs examples - nodejs programs

This is exactly how Node.js works. As soon as "File uploaded" appears, a function known as a callback function is called and carries out actions (here, the callback function displays the file).

  // // Identical result to the previous code

var callback = function (error, response, body) {
console.log ("Hey Wikitechy File uploaded!");
});

request (‘http://www.site.com/file.zip',callback);

console.log ("I do other things while I’m waiting… "); 
Related nodejs article tags - node js - node js tutorial - node js examples

nodejs sample code :

learn nodejs - nodejs tutorial - nodejs sample code - nodejs example programs

learn nodejs - nodejs tutorial - nodejs sample code - nodejs examples - nodejs programs

  • Line 1
    • Loading http module
    • It is required to work with HTTP request and response
    • It is required to create HTTP Server
  • Line 2
    • Create server using createServer() function
    • It takes a callback as parameter . It takes HTTP request and response as paramtere
    • Callback got two input parameter .
    • Both input parameters are readable and writeable stream
  • Line 4
    • Writing response header
    • It takes a JSON object as optional second parameter
    • second parameter contains informations like
    • Content Length
    • Content Type
    • Connection
    • Accept Type
learn nodejs - nodejs tutorial - nodejs online - nodejs example programs
  • Line 5-6
    • Writing data in response
    • Data can be written in form of string or buffer
    • ServerResponse.end indicates the communication has been finished
  • Line 9
    • createServer() method is finished with chained http.Server.listen() method
    • It specifies port number on which request will be listen Optional host name
  • Line 10
    • Printing a message
Related nodejs article tags - node js - node js tutorial - node js examples

nodejs workflow :

learn nodejs - nodejs tutorial - nodejs workflow - nodejs example programs

learn nodejs - nodejs tutorial - nodejs workflow - nodejs examples - nodejs programs

  • It works on single thread
  • It handles all request asynchronously on same thread
  • It does not create new thread for each request which is very unlikely like other web servers
  • It does not wait to complete a request

node js - Asynchronous Vs Event-Driven :

  • Asynchronous code execution -
    • Not all code is executed in the same order it is written
    • Node (and you) divide the code into small pieces and fire them in parallel
    • Typically the code announces its state of execution (or completion) via events
  • Event-Driven code execution -
    • A code block gets into the queue of execution when an event happens
    • ------------- It gets executed on its turn
    • Anyone can raise (or listen to) an event
    • ------------- System
      ------------- Some library (module)
      ------------- Your code
    • You have the choice (and ways) to attach a code block to an event
    • ------------- Also known as event callbacks
learn node js - node js tutorial - node js event driven code execution -  node js programs

This wikitechy technological portal provides you whole lot of information related to the topics such as mongodb tutorial , what is node js , express js tutorial , node js tutorial pdf , learn node js , node js tutorial for beginners , node js tutorial w3schools , node js express , javascript for beginners , node js express tutorial , node js tutorial point , node js book , node js server , note js , node js mongodb , what is node js used for , why node js , node tutorial , node js basics , tutorialspoint node js , node express , node js sample application , nodeschool , node js for beginners , express tutorial , node js application , use of node js , npm tutorial , node js org , node js training , node js online training , node js tutorial beginner , how to use node js , node js hello world , express node js , node js mongodb tutorial , nodejs http , why use node js

Related Searches to Node.js StringDecoder

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.

×