SlideShare a Scribd company logo
1 of 28
Node Js
Everything which you should know
Node.js for Beginners



Event programming can be overwhelming for
  beginners, which can make Node.js difficult
  to get started with. But don’t let that
  discourage you, In this article, I will teach
  you some of the basics of Node.js and
  explain why it has become so popular.
Introduction
To start using Node.js, you must first
  understand the differences between Node.js
  and traditional server-side scripting
  environments (eg: PHP, Python, Ruby, etc).
Asynchronous Programming
Chances are good that you are familiar with asynchronous programming; it is,
   after all, the “A” in Ajax. Every function in Node.js is asynchronous.
   Therefore, everything that would normally block the thread is instead
   executed in the background. This is the most important thing to
   remember about Node.js. For example, if you are reading a file on the file
   system, you have to specify a callback function that is executed when the
   read operation has completed.




"Node.js uses a module architecture to simplify the
  creation of complex applications."
You are doing Everything!
Node.js is only an environment – meaning that you have to
  do everything yourself. There is not a default HTTP
  server, or any server for that matter. This can be
  overwhelming for new users, but the payoff is a high
  performing web app. One script handles all
  communication with the clients. This considerably
  reduces the number of resources used by the
  application. For example, here is the code for a simple
  Node.js application:
Examples
Node js                        PHP
var i, a, b, c, max;           $a = null; $b = null; $c = null; $i = null;
                               $max = 1000000000;
max = 1000000000;

                               $start = microtime(true);
var d = Date.now();

                               for ($i = 0; $i < $max; $i++) {
for (i = 0; i < max; i++) {
                                   $a = 1234 + 5678 + $i;
    a = 1234 + 5678 + i;
                                   $b = 1234 * 5678 + $i;
    b = 1234 * 5678 + i;
                                   $c = 1234 / 2 + $i;
    c = 1234 / 2 + i;
                               }
}

                               var_dump(microtime(true) - $start);
console.log(Date.now() - d);
The following table lists the response times, in
milliseconds, for these two simple applications:




   Number of iterations   Node.js    PHP

   100                    2.00       0.14

   10’000                 3.00       10.53

   1’000’000              15.00      1119.24

   10’000’000             143.00     10621.46

   1’000’000’000          11118.00   1036272.19
I executed the two apps from the command
   line so that no server would delay the apps’
   execution. I ran each test ten times and
   averaged the results. PHP is notably faster
   with a smaller amount of iterations, but that
   advantage quickly dissolves as the number of
   iterations increases. When all is said and
   done, PHP is 93% slower than Node.js!


Node.js is fast, but you will need to learn a few
 things in order to use it properly.
Modules
Node.js uses a module architecture to simply
 the creation of complex applications. Each
 module contains a set of functions related
 to the “subject” of the module.


Including a module is easy; simply call the
  require() function, like this


var variable_name('module_name');
Global Scope
Node is a JavaScript environment running in
 Google’s V8 JavaScript engine.


globalVariable = 1;
globalFunction = function () { ... };
Installing New Module


Node.js has a package manager, called Node Package
  Manager (NPM). It is automatically installed with
  Node.js, and you use NPM to install new modules. To
  install a module, open your terminal/command line,
  navigate to the desired folder, and execute the
  following command:



npm install module_name
Let move ahead to
Javascript Framework
er Frameworks
ower,Railway,Flatlron, etc




                               Client Frameworks
                             Backbone, Angular, Ember, etc




        Real-time Frameworks
        Derby, meteor, SocketStream
Thick Server -
Websites
(eg, meetup) Most
functionality is still on
server, but client pages are
highly interactive and may
use MVC for organization.
Cutting -Edge Present
Thick-client: Web Apps, Mobile
(eg, gmail) Most functionality on
client. The server is just REST
service marshalling data
Little coding, large
pay-off. Great for
games.
Node.js(Server)
    Frameworks
Why we use a Node Framework ?

Why not vanilla
 Node, or         •Module version compatibilities
 Express?         •Boilerplate code
                  •Authentication
                  •Database setup
                  •Grunt/Make tasks like minification,
                    css/js compiling (Coffeescript,
                    LESS, Stylus, etc)
                  •Socket.io
                  •And much more
Express
                                                    Railway
>Express is a minimal and flexible        >Railway is the Node.JS MVC
node.js web application framework,        framework based on ExpressJS, fully
providing a robust set of features for    ExpressJS-compatible. It allows you
building single and multi-page, and       to build web applications in a similar
hybrid web applications.                  manner as in Ruby On Rails.


 Tower                                   Flatlron
                                          No one agrees on frameworks. It's
>Full Stack Web Framework for            difficult to get consensus on how
   Node.js and the Browser. Built        much or how little a framework
   on top of Node's Connect and          should do. Flatiron's approach is to
   Express, modeled after Ruby on        package simple to use yet full
   Rails. Built for the client and       featured components and let
   server from the ground up.            developers subtract or add what
                                         they want.
Derby
  MVC framework making it easy to
   write realtime, collaborative
applications that run in both Node.js
           and browsers.




 Meteor

Meteor is an open-source platform for
building top-quality web apps in a
fraction of the time, whether you're an
expert developer or just getting
started.
18 Reasons Developers Are Using It for Cloud,
                        Mobile

                              Two Third
        Two-thirds of Americans access the Web through
       mobile devices, according to Engine Yard research



Thirty-Four Percent



   And 34 percent of the world's top 100 Websites are using HTML5.
The Rise of the real-time
                Web
     Engine Yard says the growth of mobile plus the popularity of
    HTML5 equals the rise of the real-time Web. And the real-time
        Web requires real-time technology, such as Node.js.

 Event-Driven:- Node.js is a development framework that uses an event-driven, non-blocking I/O.




Built on Javascript :- Node.js is built on JavaScript to unify front-end and server-side architectures.




High Performance :- Node.js is ideal for high-performance, highly scalable, distributed real-time Web
applications.
GitHub Status :- Node.js is the second-most-watched
repository on the GitHub Web-based hosting service-second only
                         to Bootstrap.

 Ruby on Rails :- Node.js is more watched than Ruby on Rails on GitHub. Bootstrap is first, Node.js second,
 jQuery third and Rails fourth.




Node Package Manager :- Node Package Manager or NPM is a package manager and distribution system for
Node.js. NPM has 12,000 modules and 3,800 active package authors.
LinkedIn
  LinkedIn is a prominent user of Node.js. On
   the server side, LinkedIn's entire mobile
software stack is completely built in Node.js.
 The company went from running 15 servers
with 15 instances on each physical machine to
just four instances that can handle two times
                  the traffic.
Walmart              Ebay

Walmart re-           eBay recently launched ql.io
                      , a gateway for HTTP APIs,
 engineered its       using Node.js as the
 mobile app to be     runtime stack. eBay was
 powered by Node.js   able to tune a regular
 and pushed all its   quality Ubuntu workstation
                      to handle more than
 JavaScript           120,000 active connections
 processing to the    per Node.js process with
 server.              each connection consuming
                      about 2K of memory.
Key Apps
Node.js is a good choice for building
 networked multiplayer games, interactive
 Websites and tools, Web analytics and online
 chat systems.
Why Developer Love Node.js
Reason 1:
It's JavaScript, the language of the Web.
Reason 2:
It supports code reuse at every level: browser, server side
    and database.
Reason 3:
It has a strong, passionate community.
Reason 4:
It offers performance and scalability.
Reason 5:
It leads to developer happiness.

More Related Content

What's hot

Node js training (1)
Node js training (1)Node js training (1)
Node js training (1)Ashish Gupta
 
Introduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azureIntroduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azureColin Mackay
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS Ganesh Kondal
 
Introduction to REST API with Node.js
Introduction to REST API with Node.jsIntroduction to REST API with Node.js
Introduction to REST API with Node.jsYoann Gotthilf
 
Nodejs getting started
Nodejs getting startedNodejs getting started
Nodejs getting startedTriet Ho
 
Node.js an introduction
Node.js   an introductionNode.js   an introduction
Node.js an introductionMeraj Khattak
 
Node js - Enterprise Class
Node js - Enterprise ClassNode js - Enterprise Class
Node js - Enterprise ClassGlenn Block
 
NodeJS ecosystem
NodeJS ecosystemNodeJS ecosystem
NodeJS ecosystemYukti Kaura
 
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
JavaScript as a Server side language (NodeJS): JSConf 2011, DhakaJavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
JavaScript as a Server side language (NodeJS): JSConf 2011, DhakaNurul Ferdous
 
Introduction to node.js by jiban
Introduction to node.js by jibanIntroduction to node.js by jiban
Introduction to node.js by jibanJibanananda Sana
 

What's hot (20)

Nodejs server lesson 3
 Nodejs server lesson 3 Nodejs server lesson 3
Nodejs server lesson 3
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Nodejs basics
Nodejs basicsNodejs basics
Nodejs basics
 
Node js training (1)
Node js training (1)Node js training (1)
Node js training (1)
 
NodeJS
NodeJSNodeJS
NodeJS
 
Node js
Node jsNode js
Node js
 
Introduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azureIntroduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azure
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS
 
Introduction to REST API with Node.js
Introduction to REST API with Node.jsIntroduction to REST API with Node.js
Introduction to REST API with Node.js
 
Node js Introduction
Node js IntroductionNode js Introduction
Node js Introduction
 
Node js projects
Node js projectsNode js projects
Node js projects
 
Nodejs getting started
Nodejs getting startedNodejs getting started
Nodejs getting started
 
Node.js an introduction
Node.js   an introductionNode.js   an introduction
Node.js an introduction
 
Node js
Node jsNode js
Node js
 
Node js - Enterprise Class
Node js - Enterprise ClassNode js - Enterprise Class
Node js - Enterprise Class
 
NodeJS ecosystem
NodeJS ecosystemNodeJS ecosystem
NodeJS ecosystem
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
 
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
JavaScript as a Server side language (NodeJS): JSConf 2011, DhakaJavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
 
Introduction to node.js by jiban
Introduction to node.js by jibanIntroduction to node.js by jiban
Introduction to node.js by jiban
 

Similar to Node.js uses asynchronous programming and modules to simplify complex applications

Building Applications With the MEAN Stack
Building Applications With the MEAN StackBuilding Applications With the MEAN Stack
Building Applications With the MEAN StackNir Noy
 
Day in a life of a node.js developer
Day in a life of a node.js developerDay in a life of a node.js developer
Day in a life of a node.js developerEdureka!
 
Day In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperDay In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperEdureka!
 
Node.js Web Development .pdf
Node.js Web Development .pdfNode.js Web Development .pdf
Node.js Web Development .pdfAbanti Aazmin
 
All You Need to Know About Using Node.pdf
All You Need to Know About Using Node.pdfAll You Need to Know About Using Node.pdf
All You Need to Know About Using Node.pdfiDataScientists
 
Kalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect GuideKalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect GuideKalp Corporate
 
Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS drupalcampest
 
Node.js and the MEAN Stack Building Full-Stack Web Applications.pdf
Node.js and the MEAN Stack Building Full-Stack Web Applications.pdfNode.js and the MEAN Stack Building Full-Stack Web Applications.pdf
Node.js and the MEAN Stack Building Full-Stack Web Applications.pdflubnayasminsebl
 
Create Restful Web Application With Node.js Express Framework
Create Restful Web Application With Node.js Express FrameworkCreate Restful Web Application With Node.js Express Framework
Create Restful Web Application With Node.js Express FrameworkEdureka!
 
Net core vs. node.js what to choose when
Net core vs. node.js  what to choose when Net core vs. node.js  what to choose when
Net core vs. node.js what to choose when Katy Slemon
 
What is Node.js_ Where, When & How To Use It.pdf
What is Node.js_ Where, When & How To Use It.pdfWhat is Node.js_ Where, When & How To Use It.pdf
What is Node.js_ Where, When & How To Use It.pdfSmith Daniel
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginnersEnoch Joshua
 
NodeJS : Communication and Round Robin Way
NodeJS : Communication and Round Robin WayNodeJS : Communication and Round Robin Way
NodeJS : Communication and Round Robin WayEdureka!
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN StackRob Davarnia
 

Similar to Node.js uses asynchronous programming and modules to simplify complex applications (20)

Building Applications With the MEAN Stack
Building Applications With the MEAN StackBuilding Applications With the MEAN Stack
Building Applications With the MEAN Stack
 
Day in a life of a node.js developer
Day in a life of a node.js developerDay in a life of a node.js developer
Day in a life of a node.js developer
 
Day In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperDay In A Life Of A Node.js Developer
Day In A Life Of A Node.js Developer
 
Node.js Web Development .pdf
Node.js Web Development .pdfNode.js Web Development .pdf
Node.js Web Development .pdf
 
All You Need to Know About Using Node.pdf
All You Need to Know About Using Node.pdfAll You Need to Know About Using Node.pdf
All You Need to Know About Using Node.pdf
 
Nodejs
NodejsNodejs
Nodejs
 
Kalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect GuideKalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect Guide
 
Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS
 
Node.js and the MEAN Stack Building Full-Stack Web Applications.pdf
Node.js and the MEAN Stack Building Full-Stack Web Applications.pdfNode.js and the MEAN Stack Building Full-Stack Web Applications.pdf
Node.js and the MEAN Stack Building Full-Stack Web Applications.pdf
 
Nodejs
NodejsNodejs
Nodejs
 
Create Restful Web Application With Node.js Express Framework
Create Restful Web Application With Node.js Express FrameworkCreate Restful Web Application With Node.js Express Framework
Create Restful Web Application With Node.js Express Framework
 
Net core vs. node.js what to choose when
Net core vs. node.js  what to choose when Net core vs. node.js  what to choose when
Net core vs. node.js what to choose when
 
What is Node.js_ Where, When & How To Use It.pdf
What is Node.js_ Where, When & How To Use It.pdfWhat is Node.js_ Where, When & How To Use It.pdf
What is Node.js_ Where, When & How To Use It.pdf
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginners
 
Beginners Node.js
Beginners Node.jsBeginners Node.js
Beginners Node.js
 
Proposal
ProposalProposal
Proposal
 
NodeJS : Communication and Round Robin Way
NodeJS : Communication and Round Robin WayNodeJS : Communication and Round Robin Way
NodeJS : Communication and Round Robin Way
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
 
Node J pdf.docx
Node J pdf.docxNode J pdf.docx
Node J pdf.docx
 
Node J pdf.docx
Node J pdf.docxNode J pdf.docx
Node J pdf.docx
 

Node.js uses asynchronous programming and modules to simplify complex applications

  • 1. Node Js Everything which you should know
  • 2. Node.js for Beginners Event programming can be overwhelming for beginners, which can make Node.js difficult to get started with. But don’t let that discourage you, In this article, I will teach you some of the basics of Node.js and explain why it has become so popular.
  • 3. Introduction To start using Node.js, you must first understand the differences between Node.js and traditional server-side scripting environments (eg: PHP, Python, Ruby, etc).
  • 4. Asynchronous Programming Chances are good that you are familiar with asynchronous programming; it is, after all, the “A” in Ajax. Every function in Node.js is asynchronous. Therefore, everything that would normally block the thread is instead executed in the background. This is the most important thing to remember about Node.js. For example, if you are reading a file on the file system, you have to specify a callback function that is executed when the read operation has completed. "Node.js uses a module architecture to simplify the creation of complex applications."
  • 5. You are doing Everything! Node.js is only an environment – meaning that you have to do everything yourself. There is not a default HTTP server, or any server for that matter. This can be overwhelming for new users, but the payoff is a high performing web app. One script handles all communication with the clients. This considerably reduces the number of resources used by the application. For example, here is the code for a simple Node.js application:
  • 6. Examples Node js PHP var i, a, b, c, max; $a = null; $b = null; $c = null; $i = null; $max = 1000000000; max = 1000000000; $start = microtime(true); var d = Date.now(); for ($i = 0; $i < $max; $i++) { for (i = 0; i < max; i++) { $a = 1234 + 5678 + $i; a = 1234 + 5678 + i; $b = 1234 * 5678 + $i; b = 1234 * 5678 + i; $c = 1234 / 2 + $i; c = 1234 / 2 + i; } } var_dump(microtime(true) - $start); console.log(Date.now() - d);
  • 7. The following table lists the response times, in milliseconds, for these two simple applications: Number of iterations Node.js PHP 100 2.00 0.14 10’000 3.00 10.53 1’000’000 15.00 1119.24 10’000’000 143.00 10621.46 1’000’000’000 11118.00 1036272.19
  • 8. I executed the two apps from the command line so that no server would delay the apps’ execution. I ran each test ten times and averaged the results. PHP is notably faster with a smaller amount of iterations, but that advantage quickly dissolves as the number of iterations increases. When all is said and done, PHP is 93% slower than Node.js! Node.js is fast, but you will need to learn a few things in order to use it properly.
  • 9. Modules Node.js uses a module architecture to simply the creation of complex applications. Each module contains a set of functions related to the “subject” of the module. Including a module is easy; simply call the require() function, like this var variable_name('module_name');
  • 10. Global Scope Node is a JavaScript environment running in Google’s V8 JavaScript engine. globalVariable = 1; globalFunction = function () { ... };
  • 11. Installing New Module Node.js has a package manager, called Node Package Manager (NPM). It is automatically installed with Node.js, and you use NPM to install new modules. To install a module, open your terminal/command line, navigate to the desired folder, and execute the following command: npm install module_name
  • 12. Let move ahead to Javascript Framework
  • 13. er Frameworks ower,Railway,Flatlron, etc Client Frameworks Backbone, Angular, Ember, etc Real-time Frameworks Derby, meteor, SocketStream
  • 15. (eg, meetup) Most functionality is still on server, but client pages are highly interactive and may use MVC for organization.
  • 16. Cutting -Edge Present Thick-client: Web Apps, Mobile (eg, gmail) Most functionality on client. The server is just REST service marshalling data
  • 17. Little coding, large pay-off. Great for games.
  • 18. Node.js(Server) Frameworks
  • 19. Why we use a Node Framework ? Why not vanilla Node, or •Module version compatibilities Express? •Boilerplate code •Authentication •Database setup •Grunt/Make tasks like minification, css/js compiling (Coffeescript, LESS, Stylus, etc) •Socket.io •And much more
  • 20. Express Railway >Express is a minimal and flexible >Railway is the Node.JS MVC node.js web application framework, framework based on ExpressJS, fully providing a robust set of features for ExpressJS-compatible. It allows you building single and multi-page, and to build web applications in a similar hybrid web applications. manner as in Ruby On Rails. Tower Flatlron No one agrees on frameworks. It's >Full Stack Web Framework for difficult to get consensus on how Node.js and the Browser. Built much or how little a framework on top of Node's Connect and should do. Flatiron's approach is to Express, modeled after Ruby on package simple to use yet full Rails. Built for the client and featured components and let server from the ground up. developers subtract or add what they want.
  • 21. Derby MVC framework making it easy to write realtime, collaborative applications that run in both Node.js and browsers. Meteor Meteor is an open-source platform for building top-quality web apps in a fraction of the time, whether you're an expert developer or just getting started.
  • 22. 18 Reasons Developers Are Using It for Cloud, Mobile Two Third Two-thirds of Americans access the Web through mobile devices, according to Engine Yard research Thirty-Four Percent And 34 percent of the world's top 100 Websites are using HTML5.
  • 23. The Rise of the real-time Web Engine Yard says the growth of mobile plus the popularity of HTML5 equals the rise of the real-time Web. And the real-time Web requires real-time technology, such as Node.js. Event-Driven:- Node.js is a development framework that uses an event-driven, non-blocking I/O. Built on Javascript :- Node.js is built on JavaScript to unify front-end and server-side architectures. High Performance :- Node.js is ideal for high-performance, highly scalable, distributed real-time Web applications.
  • 24. GitHub Status :- Node.js is the second-most-watched repository on the GitHub Web-based hosting service-second only to Bootstrap. Ruby on Rails :- Node.js is more watched than Ruby on Rails on GitHub. Bootstrap is first, Node.js second, jQuery third and Rails fourth. Node Package Manager :- Node Package Manager or NPM is a package manager and distribution system for Node.js. NPM has 12,000 modules and 3,800 active package authors.
  • 25. LinkedIn LinkedIn is a prominent user of Node.js. On the server side, LinkedIn's entire mobile software stack is completely built in Node.js. The company went from running 15 servers with 15 instances on each physical machine to just four instances that can handle two times the traffic.
  • 26. Walmart Ebay Walmart re- eBay recently launched ql.io , a gateway for HTTP APIs, engineered its using Node.js as the mobile app to be runtime stack. eBay was powered by Node.js able to tune a regular and pushed all its quality Ubuntu workstation to handle more than JavaScript 120,000 active connections processing to the per Node.js process with server. each connection consuming about 2K of memory.
  • 27. Key Apps Node.js is a good choice for building networked multiplayer games, interactive Websites and tools, Web analytics and online chat systems.
  • 28. Why Developer Love Node.js Reason 1: It's JavaScript, the language of the Web. Reason 2: It supports code reuse at every level: browser, server side and database. Reason 3: It has a strong, passionate community. Reason 4: It offers performance and scalability. Reason 5: It leads to developer happiness.