Node.js is an asynchronous event-driven JavaScript runtime that uses non-blocking I/O to build scalable network applications. It allows for the creation of web servers and networking tools using a event-driven, non-blocking I/O model rather than the traditional threaded model. Node.js is popular because it uses JavaScript and allows code reuse on both the server-side and client-side, offers high performance and scalability for real-time applications, and has a large passionate community supporting its use.
2. Node.js for Beginners
Event programming can be overwhelming for
beginners, which can make Node.js difficult
to get started with. But dont 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
10000 3.00 10.53
1000000 15.00 1119.24
10000000 143.00 10621.46
1000000000 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
Googles 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
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.