Introduction to node.js by jiban
-
Upload
jibanananda-sana -
Category
Technology
-
view
1.340 -
download
1
description
Transcript of Introduction to node.js by jiban
![Page 2: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/2.jpg)
Plan
• What is Node.JS• Event Driven• Blocking Vs. No Blocking• What can I do in node• Install node.js• A simple node.js example• Create a web Server using Node.js• Some node.js frameworks• A demo with express.js• Who Uses node.js
![Page 3: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/3.jpg)
What is Node?
• JavaScript based software system• Event driven• Non- blocking• Launched in 2009• Founded by Ryan Dahl
![Page 4: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/4.jpg)
I/O Event-loop based server
• A tale about bunnies, hamsters and Squids…
![Page 5: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/5.jpg)
A hamster visiting your site
Single threaded bunny
(a happy bunny)
Your web server
![Page 6: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/6.jpg)
Impatient hamsters
Single threaded bunny
Your web server
(a busy bunny!)
![Page 7: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/7.jpg)
Multi-threaded bunny
Your web server
Fetching database (2s)
Consuming Service (3s)
Writing to a file (3s)
![Page 8: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/8.jpg)
Event-loop based server
Hyperactive squid
Constantly check who is idle doing nothing or waiting
![Page 9: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/9.jpg)
Node.js runs on the event loop
• The event loop keeps on running. Checking for new events, so it can call callbacks for those events.
![Page 10: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/10.jpg)
Blocking vs. Non-Blocking
Doctor’s Surgery vs. Fast-food Outlet
![Page 11: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/11.jpg)
Doctor’s Surgery(Blocking Process)
![Page 12: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/12.jpg)
Fast-food Outlet (Non-blocking Process)
![Page 13: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/13.jpg)
Non-Blocking? Blocking? I’m so confused
• By introducing callbacks. Node can move on to other requests and whenever the callback is called, node will process is.
• You should read non-blocking code as « put function and params in queue and fire callback when you reach the end of the queue »
• Blocking= return Non-Blocking= no return. Only callbacks
![Page 14: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/14.jpg)
Well, That’s Node.js
![Page 15: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/15.jpg)
What Can I Do in Node?
• Anything you want!• Chat servers, Analytics & Crazy fast backends• Socket.io library is a wicked way to build real
time apps• Build a social Network! LinkedIn, Dropbox all
using Node.js
![Page 16: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/16.jpg)
Using Modules
• In node.js require(‘ ’) is using a lot.• Require is basically a way to import modules
to your application. Modules are basically classes.
• They are a module of code that contain functions which have been exported.
• Exported functions are basically public.
![Page 17: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/17.jpg)
Install node.js
• Go to the NodeJS home page• Click install to download the .msi installer
package• Run it and follow the instrucitons, you now
have NPM (node package manager) and Node.js installed
• Reset your computer to get everything working in your command-line interface (CLI)
![Page 18: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/18.jpg)
A simple node.js applicationvar http = require("http");
var server = http.createServer();server.listen(8888);
function say(word) { console.log(word);}
function execute(someFunction, value) { someFunction(value);}
execute(say, "Beautiful Bangladesh");
![Page 19: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/19.jpg)
Creating a web server with
node.js
var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type':
'text/plain'}); res.end('Hello World\n'); }).listen(1337, "127.0.0.1"); console.log('Server running at
http://127.0.0.1:1337/');
![Page 20: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/20.jpg)
![Page 21: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/21.jpg)
Node.js Frameworks
Node.js is one of the most popular javascript framework that allow to build scalable network web applications. Node.js contains a different kind of frameworks such as MVC framework, full-stack framework, REST API and generators, lots of libraries as server library that making it possible to sun a web server without use of external software such as Apache and Lighttpd. These frameworks makes it more user-friendly and easy to use, also supports a large number of features and functionality to develop huge web applications in just follow few steps.
![Page 22: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/22.jpg)
Sails.js
Sails is one of the excellent framework that make it easy to develop custom, enterprise-grade and modern Node.js apps, also it’s good for building charts, dashboards and multiple games.
![Page 23: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/23.jpg)
Total.js
Total.js is another great framework for Node.js helps to create web pages and web applications, also supports MVC architecture. This is the open source modern framework for building websites using HTML, javaScript and CSS.
![Page 24: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/24.jpg)
Partial.js
Partial js, framework for Node.js, Using HTML, CSS and JavaScript developers can build large scale of web applications and websites. Features and architecture are same as total.js.
![Page 25: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/25.jpg)
Koa.js
This framework for Node.js is designed by team of Express. Koa.js is next generation tool, which aims to be a smaller, more expressive, and more robust foundation for web applications and APIs.
![Page 26: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/26.jpg)
Locomotive.js
Locomotive supports MVC pattern, RESTful routes also builds on Express. This is one of the most powerful web framework for Node.js, present great features : -1) convention over configuration2) Routing Helpers3) MVC Architecture4) connect to any Database and more.
![Page 27: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/27.jpg)
Express.js
Most Popular web framework for Node.js over the internet and among web developers. Using robust set of features developers can create single and multi-page, and hybrid web applications.
![Page 28: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/28.jpg)
Flatiron.js
Flatiron.js is also a modern and next generation web framework for developers that helps to building impressive and huge web application with its advance features.
![Page 29: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/29.jpg)
Express.io
Express.io is realtime web framework for Node.js. And also supports MVC architecture for create web applications.
![Page 30: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/30.jpg)
Socket Stream
Socket stream is dedicated to building real time single page applications with its fast and modular nature.
![Page 31: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/31.jpg)
Geddy.js
Geddy.js is simple, structured and original MVC web framework for Node.js for building advance web application.
![Page 32: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/32.jpg)
Demo
Create An Application Using
Express.js
![Page 33: Introduction to node.js by jiban](https://reader036.fdocuments.in/reader036/viewer/2022081511/554a08ceb4c905507a8b5701/html5/thumbnails/33.jpg)
Companies using node
https://github.com/joyent/node/wiki/Projects,-Applications,-and-Companies-Using-Node