SlideShare a Scribd company logo
The Server-side JavaScript
Van-Duyet Le
me@duyetdev.com
Introduce about
What to expect ahead….
Introduction
Some (Confusing) Theory
5 Examples
A couple of weird diagrams
2 Pics showing unbelievable benchmarks
Some stuff from Internet
And Homer Simpson
Background
 V8 is an open source JavaScript engine developed by
Google. Its written in C++ and is used in Google Chrome
Browser.
 Node.js runs on V8.
 It was created by Ryan Dahl in 2009.
 Latest version is 4.0.0
 Is Open Source. It runs well on Linux systems, can also run
on Windows systems.
Introduction: Basic
In simple words Node.js is ‘server-side
JavaScript’.
In not-so-simple words Node.js is a high-performance
network applications framework, well
optimized for high concurrent environments.
It’s a command line tool.
In ‘Node.js’ , ‘.js’ doesn’t mean that its solely written
JavaScript. It is 40% JS and 60% C++.
From the official site:
‘Node's goal is to provide an easy way to build
scalable network programs’ - (from nodejs.org!)
Introduction: Advanced (& Confusing)
Node.js uses an event-driven, non-blocking I/O
model, which makes it lightweight. (from
nodejs.org!)
It makes use of event-loops via JavaScript’s
callback functionality to implement the non-
blocking I/O.
Programs for Node.js are written in JavaScript but
not in the same JavaScript we are use to.
Everything inside Node.js runs in a single-thread.
Example-1: Getting Started & Hello World
Install/build Node.js.
Open your favorite editor and start typing
JavaScript.
When you are done, open cmd/terminal and type
this:
‘node your_file.js’
Here is a simple example, which prints ‘hello world’
var sys = require(“sys”);
setTimeout(function(){
sys.puts(“world”);},3000);
sys.puts(“hello”);
//it prints ‘hello’ first and waits for 3 seconds and then
prints ‘world’
Some Theory: Event-loops
Event-loops are the core of event-driven programming,
almost all the UI programs use event-loops to track the
user event, for example: Clicks, Ajax Requests etc.
Client
Event loop
(main thread)
C++
Threadpool
(worker
threads)
Clients send HTTP requests
to Node.js server
An Event-loop is woken up by OS,
passes request and response objects
to the thread-pool
Long-running jobs run
on worker threads
Response is sent
back to main thread
via callback
Event loop returns
result to client
Some Theory: Non-Blocking I/O
Traditional I/O
var result = db.query(“select x from table_Y”);
doSomethingWith(result); //wait for result!
doSomethingWithOutResult(); //execution is blocked!
Non-traditional, Non-blocking I/O
db.query(“select x from table_Y”,function (result){
doSomethingWith(result); //wait for result!
});
doSomethingWithOutResult(); //executes without any delay!
What can you do with Node.js ?
 You can create an HTTP server and print ‘hello world’
on the browser in just 4 lines of JavaScript.
 You can create a TCP server similar to HTTP server, in
just 4 lines of JavaScript.
 You can create a DNS server.
 You can create a Static File Server.
 You can create a Web Chat Application.
 Node.js can also be used for creating online games,
collaboration tools or anything which sends updates to
the user in real-time.
Example -2 &3 (HTTP Server & TCP
Server)
 Following code creates an HTTP Server and prints ‘Hello World’ on
the browser:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello Worldn'); }).listen(5000,
"127.0.0.1");
 Here is an example of a simple TCP server which listens on port
6000 and echoes whatever you send it:
var net = require('net');
net.createServer(function (socket) {
socket.write("Echo serverrn");
socket.pipe(socket); }).listen(6000, "127.0.0.1");
Node.js Ecosystem
 Node.js heavily relies on modules, in previous examples
require keyword loaded the http & net modules.
 Creating a module is easy, just put your JavaScript code in a
separate js file and include it in your code by using keyword
require, like:
var modulex = require(‘./modulex’);
 Libraries in Node.js are called packages and they can be
installed by typing
npm install “package_name”; //package should be
available in npm registry @ nmpjs.org
 NPM (Node Package Manager) comes bundled with Node.js
installation.
Example-4: Lets connect to a DB
(Mongoose)
Install mongoose using npm, elegant mongodb object
modeling for node.js
npm install mongoose
Code to retrieve all the documents from a collection:
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');
var Cat = mongoose.model('Cat', { name: String });
var kitty = new Cat({ name: 'Zildjian' });
kitty.save(function (err) {
if (err) // ...
console.log('meow');
});
When to use Node.js?
Node.js is good for creating streaming based real-
time services, web chat applications, static file
servers etc.
If you need high level concurrency and not worried
about CPU-cycles.
You can use the same language at both the places:
server-side and client-side.
Example-5: Twitter Streaming
Install nTwitter module using npm:
Npm install ntwitter
Code:
var twitter = require('ntwitter');
var twit = new twitter({
consumer_key: ‘c_key’,
consumer_secret: ‘c_secret’,
access_token_key: ‘token_key’,
access_token_secret: ‘token_secret’});
twit.stream('statuses/sample', function(stream) {
stream.on('data', function (data) {
console.log(data); });
});
Some Node.js benchmarks
Taken from:
http://code.google.com/p/node-js-vs-
apache-php-benchmark/wiki/Tests
A benchmark between Apache+PHP
and node.js, shows the response
time for 1000 concurrent connections
making 10,000 requests each, for 5
tests.
Taken from:
http://nodejs.org/jsconf2010.p
df
The benchmark shows the
response time in milli-secs
for 4 evented servers.
When to not use Node.js
When you are doing heavy and CPU intensive
calculations on server side, because event-loops
are CPU hungry.
Most of the packages are also unstable. Therefore
is not yet production ready.
Read further on disadvantages of Node.js on Quora:
http://www.quora.com/What-are-the-disadvantages-
of-using-Node-js
Appendix-1: Who is using Node.js in
production?
Yahoo! : iPad App Livestand uses Yahoo!
Manhattan framework which is based on Node.js.
LinkedIn : LinkedIn uses a combination of Node.js
and MongoDB for its mobile platform. iOS and
Android apps are based on it.
 eBay : Uses Node.js along with ql.io to help
application developers in improving eBay’s end user
experience.
Complete list can be found at:
https://github.com/joyent/node/wiki/Projects,-
Applications,-and-Companies-Using-Node
Appendix-2: Resource to get started
Watch this video at Youtube:
http://www.youtube.com/watch?v=jo_B4LTHi3I
Read the free O’reilly Book ‘Up and Running with Node.js’
@ http://ofps.oreilly.com/titles/9781449398583/
Visit www.nodejs.org for Info/News about Node.js
Watch Node.js tutorials @ http://nodetuts.com/
For Info on MongoDB:
http://www.mongodb.org/display/DOCS/Home
For anything else Google!
Appendix-3: Some Good Modules
Express – to make things simpler e.g. syntax, DB
connections.
Jade – HTML template system
Socket.IO – to create real-time apps
Nodemon – to monitor Node.js and push change
automatically
CoffeeScript – for easier JavaScript development
Introduce about Nodejs - duyetdev.com

More Related Content

What's hot

Nodejs vatsal shah
Nodejs vatsal shahNodejs vatsal shah
Nodejs vatsal shah
Vatsal N Shah
 
Node js presentation
Node js presentationNode js presentation
Node js presentationmartincabrera
 
Philly Tech Week Introduction to NodeJS
Philly Tech Week Introduction to NodeJSPhilly Tech Week Introduction to NodeJS
Philly Tech Week Introduction to NodeJS
Ross Kukulinski
 
Nodejs in Production
Nodejs in ProductionNodejs in Production
Nodejs in Production
William Bruno Moraes
 
Server Side Event Driven Programming
Server Side Event Driven ProgrammingServer Side Event Driven Programming
Server Side Event Driven Programming
Kamal Hussain
 
Node.js
Node.jsNode.js
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
jacekbecela
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
orkaplan
 
Java script at backend nodejs
Java script at backend   nodejsJava script at backend   nodejs
Java script at backend nodejs
Amit Thakkar
 
Building servers with Node.js
Building servers with Node.jsBuilding servers with Node.js
Building servers with Node.jsConFoo
 
OSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialOSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialTom Croucher
 
Node Architecture and Getting Started with Express
Node Architecture and Getting Started with ExpressNode Architecture and Getting Started with Express
Node Architecture and Getting Started with Express
jguerrero999
 
Getting started with developing Nodejs
Getting started with developing NodejsGetting started with developing Nodejs
Getting started with developing Nodejs
Phil Hawksworth
 
Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming  Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming
Tom Croucher
 
All aboard the NodeJS Express
All aboard the NodeJS ExpressAll aboard the NodeJS Express
All aboard the NodeJS Express
David Boyer
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
David Padbury
 
Comet with node.js and V8
Comet with node.js and V8Comet with node.js and V8
Comet with node.js and V8
amix3k
 
A million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scaleA million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scaleTom Croucher
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)
Chris Cowan
 

What's hot (20)

Nodejs vatsal shah
Nodejs vatsal shahNodejs vatsal shah
Nodejs vatsal shah
 
NodeJS
NodeJSNodeJS
NodeJS
 
Node js presentation
Node js presentationNode js presentation
Node js presentation
 
Philly Tech Week Introduction to NodeJS
Philly Tech Week Introduction to NodeJSPhilly Tech Week Introduction to NodeJS
Philly Tech Week Introduction to NodeJS
 
Nodejs in Production
Nodejs in ProductionNodejs in Production
Nodejs in Production
 
Server Side Event Driven Programming
Server Side Event Driven ProgrammingServer Side Event Driven Programming
Server Side Event Driven Programming
 
Node.js
Node.jsNode.js
Node.js
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Java script at backend nodejs
Java script at backend   nodejsJava script at backend   nodejs
Java script at backend nodejs
 
Building servers with Node.js
Building servers with Node.jsBuilding servers with Node.js
Building servers with Node.js
 
OSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialOSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js Tutorial
 
Node Architecture and Getting Started with Express
Node Architecture and Getting Started with ExpressNode Architecture and Getting Started with Express
Node Architecture and Getting Started with Express
 
Getting started with developing Nodejs
Getting started with developing NodejsGetting started with developing Nodejs
Getting started with developing Nodejs
 
Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming  Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming
 
All aboard the NodeJS Express
All aboard the NodeJS ExpressAll aboard the NodeJS Express
All aboard the NodeJS Express
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
 
Comet with node.js and V8
Comet with node.js and V8Comet with node.js and V8
Comet with node.js and V8
 
A million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scaleA million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scale
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)
 

Similar to Introduce about Nodejs - duyetdev.com

Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Vikash Singh
 
Node
NodeNode
Nodejs
NodejsNodejs
NodeJS
NodeJSNodeJS
NodeJS
Alok Guha
 
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 Developer
Edureka!
 
Nodejs intro
Nodejs introNodejs intro
Nodejs intro
Ndjido Ardo BAR
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
soft-shake.ch
 
Real World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationReal World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS Application
Ben Hall
 
Kalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect GuideKalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect Guide
Kalp Corporate
 
Tech io nodejs_20130531_v0.6
Tech io nodejs_20130531_v0.6Tech io nodejs_20130531_v0.6
Tech io nodejs_20130531_v0.6
Ganesh Kondal
 
NodeJS : Communication and Round Robin Way
NodeJS : Communication and Round Robin WayNodeJS : Communication and Round Robin Way
NodeJS : Communication and Round Robin Way
Edureka!
 
Basic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.jsBasic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.js
Gary Yeh
 
Node js Modules and Event Emitters
Node js Modules and Event EmittersNode js Modules and Event Emitters
Node js Modules and Event Emitters
TheCreativedev Blog
 
Node.js: A Guided Tour
Node.js: A Guided TourNode.js: A Guided Tour
Node.js: A Guided Tour
cacois
 
Node js introduction
Node js introductionNode js introduction
Node js introductionAlex Su
 
Introduction to Node.JS
Introduction to Node.JSIntroduction to Node.JS
Introduction to Node.JS
Collaboration Technologies
 

Similar to Introduce about Nodejs - duyetdev.com (20)

Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Node
NodeNode
Node
 
Proposal
ProposalProposal
Proposal
 
Nodejs
NodejsNodejs
Nodejs
 
Node js
Node jsNode js
Node js
 
NodeJS
NodeJSNodeJS
NodeJS
 
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
 
Nodejs intro
Nodejs introNodejs intro
Nodejs intro
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
 
Real World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationReal World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS Application
 
Kalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect GuideKalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect Guide
 
Tech io nodejs_20130531_v0.6
Tech io nodejs_20130531_v0.6Tech io nodejs_20130531_v0.6
Tech io nodejs_20130531_v0.6
 
NodeJS : Communication and Round Robin Way
NodeJS : Communication and Round Robin WayNodeJS : Communication and Round Robin Way
NodeJS : Communication and Round Robin Way
 
Basic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.jsBasic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.js
 
Node js Modules and Event Emitters
Node js Modules and Event EmittersNode js Modules and Event Emitters
Node js Modules and Event Emitters
 
Node js beginner
Node js beginnerNode js beginner
Node js beginner
 
Node.js: A Guided Tour
Node.js: A Guided TourNode.js: A Guided Tour
Node.js: A Guided Tour
 
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
 

More from Van-Duyet Le

[LvDuit//Lab] Crawling the web
[LvDuit//Lab] Crawling the web[LvDuit//Lab] Crawling the web
[LvDuit//Lab] Crawling the web
Van-Duyet Le
 
CTDL&GT: Các loại danh sách liên kết
CTDL&GT: Các loại danh sách liên kếtCTDL&GT: Các loại danh sách liên kết
CTDL&GT: Các loại danh sách liên kết
Van-Duyet Le
 
Bài tập tích phân suy rộng.
Bài tập tích phân suy rộng.Bài tập tích phân suy rộng.
Bài tập tích phân suy rộng.
Van-Duyet Le
 
Tổng hợp 35 câu hỏi phần triết học kèm trả lời
Tổng hợp 35 câu hỏi phần triết học kèm trả lờiTổng hợp 35 câu hỏi phần triết học kèm trả lời
Tổng hợp 35 câu hỏi phần triết học kèm trả lời
Van-Duyet Le
 
Hướng dẫn giải bài tập chuỗi - Toán cao cấp
Hướng dẫn giải bài tập chuỗi - Toán cao cấpHướng dẫn giải bài tập chuỗi - Toán cao cấp
Hướng dẫn giải bài tập chuỗi - Toán cao cấp
Van-Duyet Le
 
Giáo trình C căn bản.
Giáo trình C căn bản.Giáo trình C căn bản.
Giáo trình C căn bản.
Van-Duyet Le
 
58 công thức giải nhanh hóa học
58 công thức giải nhanh hóa học58 công thức giải nhanh hóa học
58 công thức giải nhanh hóa họcVan-Duyet Le
 
Bài tập tổng hợp dao động điều hòa - Con lắc đơn - Con lắc lò xo - Tổng hợp
Bài tập tổng hợp dao động điều hòa - Con lắc đơn - Con lắc lò xo - Tổng hợpBài tập tổng hợp dao động điều hòa - Con lắc đơn - Con lắc lò xo - Tổng hợp
Bài tập tổng hợp dao động điều hòa - Con lắc đơn - Con lắc lò xo - Tổng hợpVan-Duyet Le
 
Bài tập điện xoay chiều
Bài tập điện xoay chiềuBài tập điện xoay chiều
Bài tập điện xoay chiềuVan-Duyet Le
 
Phương pháp: 10 dạng bài tập dao động điều hòa
Phương pháp: 10 dạng bài tập dao động điều hòaPhương pháp: 10 dạng bài tập dao động điều hòa
Phương pháp: 10 dạng bài tập dao động điều hòaVan-Duyet Le
 
Trắc nghiệm điện xoay chiều
Trắc nghiệm điện xoay chiềuTrắc nghiệm điện xoay chiều
Trắc nghiệm điện xoay chiềuVan-Duyet Le
 
Con lắc đơn - Con lắc lò xo - Tổng hợp dao động - Dao động tắt dần - Dao động...
Con lắc đơn - Con lắc lò xo - Tổng hợp dao động - Dao động tắt dần - Dao động...Con lắc đơn - Con lắc lò xo - Tổng hợp dao động - Dao động tắt dần - Dao động...
Con lắc đơn - Con lắc lò xo - Tổng hợp dao động - Dao động tắt dần - Dao động...
Van-Duyet Le
 
67 Bài Tập về Phương trình mũ và Phương trình Logarit
67 Bài Tập về Phương trình mũ và Phương trình Logarit67 Bài Tập về Phương trình mũ và Phương trình Logarit
67 Bài Tập về Phương trình mũ và Phương trình Logarit
Van-Duyet Le
 
Kĩ thuật giải các loại hệ phương trình
Kĩ thuật giải các loại hệ phương trìnhKĩ thuật giải các loại hệ phương trình
Kĩ thuật giải các loại hệ phương trình
Van-Duyet Le
 
Reported Speech (NC)
Reported Speech (NC)Reported Speech (NC)
Reported Speech (NC)
Van-Duyet Le
 
3000 từ tiếng Anh thông dụng
3000 từ tiếng Anh thông dụng3000 từ tiếng Anh thông dụng
3000 từ tiếng Anh thông dụng
Van-Duyet Le
 
Thứ sáu ngày 13 với toán đồng dư.
Thứ sáu ngày 13 với toán đồng dư.Thứ sáu ngày 13 với toán đồng dư.
Thứ sáu ngày 13 với toán đồng dư.Van-Duyet Le
 
GEN - ADN - Nhân Đôi ADN - Phiên Mã - Dịch Mã
GEN - ADN - Nhân Đôi ADN - Phiên Mã - Dịch MãGEN - ADN - Nhân Đôi ADN - Phiên Mã - Dịch Mã
GEN - ADN - Nhân Đôi ADN - Phiên Mã - Dịch MãVan-Duyet Le
 
[Sinh 12] 140 câu tiến hóa
[Sinh 12] 140 câu tiến hóa[Sinh 12] 140 câu tiến hóa
[Sinh 12] 140 câu tiến hóaVan-Duyet Le
 
Toán DH (THPT Lê Lợi)
Toán DH (THPT Lê Lợi)Toán DH (THPT Lê Lợi)
Toán DH (THPT Lê Lợi)
Van-Duyet Le
 

More from Van-Duyet Le (20)

[LvDuit//Lab] Crawling the web
[LvDuit//Lab] Crawling the web[LvDuit//Lab] Crawling the web
[LvDuit//Lab] Crawling the web
 
CTDL&GT: Các loại danh sách liên kết
CTDL&GT: Các loại danh sách liên kếtCTDL&GT: Các loại danh sách liên kết
CTDL&GT: Các loại danh sách liên kết
 
Bài tập tích phân suy rộng.
Bài tập tích phân suy rộng.Bài tập tích phân suy rộng.
Bài tập tích phân suy rộng.
 
Tổng hợp 35 câu hỏi phần triết học kèm trả lời
Tổng hợp 35 câu hỏi phần triết học kèm trả lờiTổng hợp 35 câu hỏi phần triết học kèm trả lời
Tổng hợp 35 câu hỏi phần triết học kèm trả lời
 
Hướng dẫn giải bài tập chuỗi - Toán cao cấp
Hướng dẫn giải bài tập chuỗi - Toán cao cấpHướng dẫn giải bài tập chuỗi - Toán cao cấp
Hướng dẫn giải bài tập chuỗi - Toán cao cấp
 
Giáo trình C căn bản.
Giáo trình C căn bản.Giáo trình C căn bản.
Giáo trình C căn bản.
 
58 công thức giải nhanh hóa học
58 công thức giải nhanh hóa học58 công thức giải nhanh hóa học
58 công thức giải nhanh hóa học
 
Bài tập tổng hợp dao động điều hòa - Con lắc đơn - Con lắc lò xo - Tổng hợp
Bài tập tổng hợp dao động điều hòa - Con lắc đơn - Con lắc lò xo - Tổng hợpBài tập tổng hợp dao động điều hòa - Con lắc đơn - Con lắc lò xo - Tổng hợp
Bài tập tổng hợp dao động điều hòa - Con lắc đơn - Con lắc lò xo - Tổng hợp
 
Bài tập điện xoay chiều
Bài tập điện xoay chiềuBài tập điện xoay chiều
Bài tập điện xoay chiều
 
Phương pháp: 10 dạng bài tập dao động điều hòa
Phương pháp: 10 dạng bài tập dao động điều hòaPhương pháp: 10 dạng bài tập dao động điều hòa
Phương pháp: 10 dạng bài tập dao động điều hòa
 
Trắc nghiệm điện xoay chiều
Trắc nghiệm điện xoay chiềuTrắc nghiệm điện xoay chiều
Trắc nghiệm điện xoay chiều
 
Con lắc đơn - Con lắc lò xo - Tổng hợp dao động - Dao động tắt dần - Dao động...
Con lắc đơn - Con lắc lò xo - Tổng hợp dao động - Dao động tắt dần - Dao động...Con lắc đơn - Con lắc lò xo - Tổng hợp dao động - Dao động tắt dần - Dao động...
Con lắc đơn - Con lắc lò xo - Tổng hợp dao động - Dao động tắt dần - Dao động...
 
67 Bài Tập về Phương trình mũ và Phương trình Logarit
67 Bài Tập về Phương trình mũ và Phương trình Logarit67 Bài Tập về Phương trình mũ và Phương trình Logarit
67 Bài Tập về Phương trình mũ và Phương trình Logarit
 
Kĩ thuật giải các loại hệ phương trình
Kĩ thuật giải các loại hệ phương trìnhKĩ thuật giải các loại hệ phương trình
Kĩ thuật giải các loại hệ phương trình
 
Reported Speech (NC)
Reported Speech (NC)Reported Speech (NC)
Reported Speech (NC)
 
3000 từ tiếng Anh thông dụng
3000 từ tiếng Anh thông dụng3000 từ tiếng Anh thông dụng
3000 từ tiếng Anh thông dụng
 
Thứ sáu ngày 13 với toán đồng dư.
Thứ sáu ngày 13 với toán đồng dư.Thứ sáu ngày 13 với toán đồng dư.
Thứ sáu ngày 13 với toán đồng dư.
 
GEN - ADN - Nhân Đôi ADN - Phiên Mã - Dịch Mã
GEN - ADN - Nhân Đôi ADN - Phiên Mã - Dịch MãGEN - ADN - Nhân Đôi ADN - Phiên Mã - Dịch Mã
GEN - ADN - Nhân Đôi ADN - Phiên Mã - Dịch Mã
 
[Sinh 12] 140 câu tiến hóa
[Sinh 12] 140 câu tiến hóa[Sinh 12] 140 câu tiến hóa
[Sinh 12] 140 câu tiến hóa
 
Toán DH (THPT Lê Lợi)
Toán DH (THPT Lê Lợi)Toán DH (THPT Lê Lợi)
Toán DH (THPT Lê Lợi)
 

Recently uploaded

Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 

Recently uploaded (20)

Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 

Introduce about Nodejs - duyetdev.com

  • 1. The Server-side JavaScript Van-Duyet Le me@duyetdev.com Introduce about
  • 2. What to expect ahead…. Introduction Some (Confusing) Theory 5 Examples A couple of weird diagrams 2 Pics showing unbelievable benchmarks Some stuff from Internet And Homer Simpson
  • 3. Background  V8 is an open source JavaScript engine developed by Google. Its written in C++ and is used in Google Chrome Browser.  Node.js runs on V8.  It was created by Ryan Dahl in 2009.  Latest version is 4.0.0  Is Open Source. It runs well on Linux systems, can also run on Windows systems.
  • 4. Introduction: Basic In simple words Node.js is ‘server-side JavaScript’. In not-so-simple words Node.js is a high-performance network applications framework, well optimized for high concurrent environments. It’s a command line tool. In ‘Node.js’ , ‘.js’ doesn’t mean that its solely written JavaScript. It is 40% JS and 60% C++. From the official site: ‘Node's goal is to provide an easy way to build scalable network programs’ - (from nodejs.org!)
  • 5. Introduction: Advanced (& Confusing) Node.js uses an event-driven, non-blocking I/O model, which makes it lightweight. (from nodejs.org!) It makes use of event-loops via JavaScript’s callback functionality to implement the non- blocking I/O. Programs for Node.js are written in JavaScript but not in the same JavaScript we are use to. Everything inside Node.js runs in a single-thread.
  • 6. Example-1: Getting Started & Hello World Install/build Node.js. Open your favorite editor and start typing JavaScript. When you are done, open cmd/terminal and type this: ‘node your_file.js’ Here is a simple example, which prints ‘hello world’ var sys = require(“sys”); setTimeout(function(){ sys.puts(“world”);},3000); sys.puts(“hello”); //it prints ‘hello’ first and waits for 3 seconds and then prints ‘world’
  • 7. Some Theory: Event-loops Event-loops are the core of event-driven programming, almost all the UI programs use event-loops to track the user event, for example: Clicks, Ajax Requests etc. Client Event loop (main thread) C++ Threadpool (worker threads) Clients send HTTP requests to Node.js server An Event-loop is woken up by OS, passes request and response objects to the thread-pool Long-running jobs run on worker threads Response is sent back to main thread via callback Event loop returns result to client
  • 8. Some Theory: Non-Blocking I/O Traditional I/O var result = db.query(“select x from table_Y”); doSomethingWith(result); //wait for result! doSomethingWithOutResult(); //execution is blocked! Non-traditional, Non-blocking I/O db.query(“select x from table_Y”,function (result){ doSomethingWith(result); //wait for result! }); doSomethingWithOutResult(); //executes without any delay!
  • 9. What can you do with Node.js ?  You can create an HTTP server and print ‘hello world’ on the browser in just 4 lines of JavaScript.  You can create a TCP server similar to HTTP server, in just 4 lines of JavaScript.  You can create a DNS server.  You can create a Static File Server.  You can create a Web Chat Application.  Node.js can also be used for creating online games, collaboration tools or anything which sends updates to the user in real-time.
  • 10. Example -2 &3 (HTTP Server & TCP Server)  Following code creates an HTTP Server and prints ‘Hello World’ on the browser: var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Worldn'); }).listen(5000, "127.0.0.1");  Here is an example of a simple TCP server which listens on port 6000 and echoes whatever you send it: var net = require('net'); net.createServer(function (socket) { socket.write("Echo serverrn"); socket.pipe(socket); }).listen(6000, "127.0.0.1");
  • 11. Node.js Ecosystem  Node.js heavily relies on modules, in previous examples require keyword loaded the http & net modules.  Creating a module is easy, just put your JavaScript code in a separate js file and include it in your code by using keyword require, like: var modulex = require(‘./modulex’);  Libraries in Node.js are called packages and they can be installed by typing npm install “package_name”; //package should be available in npm registry @ nmpjs.org  NPM (Node Package Manager) comes bundled with Node.js installation.
  • 12. Example-4: Lets connect to a DB (Mongoose) Install mongoose using npm, elegant mongodb object modeling for node.js npm install mongoose Code to retrieve all the documents from a collection: var mongoose = require('mongoose'); mongoose.connect('mongodb://localhost/test'); var Cat = mongoose.model('Cat', { name: String }); var kitty = new Cat({ name: 'Zildjian' }); kitty.save(function (err) { if (err) // ... console.log('meow'); });
  • 13. When to use Node.js? Node.js is good for creating streaming based real- time services, web chat applications, static file servers etc. If you need high level concurrency and not worried about CPU-cycles. You can use the same language at both the places: server-side and client-side.
  • 14. Example-5: Twitter Streaming Install nTwitter module using npm: Npm install ntwitter Code: var twitter = require('ntwitter'); var twit = new twitter({ consumer_key: ‘c_key’, consumer_secret: ‘c_secret’, access_token_key: ‘token_key’, access_token_secret: ‘token_secret’}); twit.stream('statuses/sample', function(stream) { stream.on('data', function (data) { console.log(data); }); });
  • 15. Some Node.js benchmarks Taken from: http://code.google.com/p/node-js-vs- apache-php-benchmark/wiki/Tests A benchmark between Apache+PHP and node.js, shows the response time for 1000 concurrent connections making 10,000 requests each, for 5 tests. Taken from: http://nodejs.org/jsconf2010.p df The benchmark shows the response time in milli-secs for 4 evented servers.
  • 16. When to not use Node.js When you are doing heavy and CPU intensive calculations on server side, because event-loops are CPU hungry. Most of the packages are also unstable. Therefore is not yet production ready. Read further on disadvantages of Node.js on Quora: http://www.quora.com/What-are-the-disadvantages- of-using-Node-js
  • 17. Appendix-1: Who is using Node.js in production? Yahoo! : iPad App Livestand uses Yahoo! Manhattan framework which is based on Node.js. LinkedIn : LinkedIn uses a combination of Node.js and MongoDB for its mobile platform. iOS and Android apps are based on it.  eBay : Uses Node.js along with ql.io to help application developers in improving eBay’s end user experience. Complete list can be found at: https://github.com/joyent/node/wiki/Projects,- Applications,-and-Companies-Using-Node
  • 18. Appendix-2: Resource to get started Watch this video at Youtube: http://www.youtube.com/watch?v=jo_B4LTHi3I Read the free O’reilly Book ‘Up and Running with Node.js’ @ http://ofps.oreilly.com/titles/9781449398583/ Visit www.nodejs.org for Info/News about Node.js Watch Node.js tutorials @ http://nodetuts.com/ For Info on MongoDB: http://www.mongodb.org/display/DOCS/Home For anything else Google!
  • 19. Appendix-3: Some Good Modules Express – to make things simpler e.g. syntax, DB connections. Jade – HTML template system Socket.IO – to create real-time apps Nodemon – to monitor Node.js and push change automatically CoffeeScript – for easier JavaScript development