introduction to nodejs and isomorphic javascript

16
Node JS and Isomorphic Javascript Jasper

Upload: chenkuo-chen

Post on 15-Jul-2015

159 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Introduction to Nodejs and Isomorphic javascript

Node JS and Isomorphic Javascript

Jasper

Page 2: Introduction to Nodejs and Isomorphic javascript

Outline

• Asynchronous Programming

• Concept of Node JS

• Revolution of Web Framework

• Isomorphic Javascript Web Framework

Page 3: Introduction to Nodejs and Isomorphic javascript

Asynchronous Programming

Task1 I/O: waiting

Task1: Data Processing

Task2: Data Processing

Task2: I/O: waiting

Page 4: Introduction to Nodejs and Isomorphic javascript

Asynchronous Programming

Task1 I/O: waitingTask 1: Data ProcessingTask 2: Data Processing

Task 1: Callback

Page 5: Introduction to Nodejs and Isomorphic javascript

Asynchronous Programming

• Compared with multithreading:

• Cons:

• Service is blocked when encountering heavy CPU computing.

• Pros:

• Don’t need to maintain thread state

• Don’t suffer from context switching

Page 6: Introduction to Nodejs and Isomorphic javascript

Asynchronous Programming

• HTTP request processed by web server.

!

!

!

!

!

route a request

query a DB

process results

write a log

format response

Page 7: Introduction to Nodejs and Isomorphic javascript

Asynchronous Programming

• Popular project based on asynchronous programming

• Node JS

• Twisted

• Tornado

Page 8: Introduction to Nodejs and Isomorphic javascript

Node JS

• Server-side JS runtime based on V8

• Single thread.

• Asynchronous programming - libuv

Page 9: Introduction to Nodejs and Isomorphic javascript

Node JS

Event Loop

Event Queue Thread Pool

Network

File System

...

CallbackEvents

Page 10: Introduction to Nodejs and Isomorphic javascript

Node JS

• As a web server on multi-core host

• Run a node JS web server process per core

• A load balancer ahead of them.

Page 11: Introduction to Nodejs and Isomorphic javascript

Traditional Web Framework

• Model View Controller(MVC)

• Rails/Django/CodeIngiter

!

!

!

!

Controller Model

View

Browser Request Execute Data

Data Returned

Data ReturnedResponse View

Browser Response

Page 12: Introduction to Nodejs and Isomorphic javascript

Modern Single Page Application

• Front-end MVC framework with pure API server.

!

!

!

!

Web App

Mobile App

API

• Pure Javascript MVC Framework

• Angular

• Ember

• Backbone

• ...

Page 13: Introduction to Nodejs and Isomorphic javascript

Modern Single Page Application

• Pros:

• Without refresh the page when browsing the page

• Separate pure data from business logic

• Cons:

• SEO

• Performance depend on users’ end devices

• Twitter

• Duplicate logic(URL routing, validation, ...etc.)

Page 14: Introduction to Nodejs and Isomorphic javascript

Isomorphic Javascript

• A concept of JS web framework that shares Javascript run on both client side and server side.

• Reuse all codes

• Flexible for developer

• Bootstrap initial page via server rendering.

• Font-end rendering/Back-end rendering

Page 15: Introduction to Nodejs and Isomorphic javascript

Isomorphic Javascript

• Web framework with Isomorphic conecpts

• Meteor - Meteor.com

• Derby

• Rendr - Airbnb

• Even use React + Flux

Page 16: Introduction to Nodejs and Isomorphic javascript

End