Vn-info meetup on Node.js
These are the slides used at VN-INFO meetup on 16 July 2014.
This meetup is the 2nd one in the Javascript serie we organized.
To have more details, please use the slides' outline at http://goo.gl/9097I6
The example codes can be found on the GitHub repo at: http://goo.gl/53x39M. Do not hesitate to patch or create the issue if you find any !
2. NODE.JS IS A PLATFORM BUILT ON CHROME'S
JAVASCRIPT RUNTIME FOR EASILY BUILDING FAST,
SCALABLE NETWORK APPLICATIONS. NODE.JS USES
AN EVENT-DRIVEN, NON-BLOCKING I/O MODELTHAT
MAKES IT LIGHTWEIGHT AND EFFICIENT, PERFECT FOR
DATA-INTENSIVE REAL-TIME APPLICATIONSTHAT RUN
ACROSS DISTRIBUTED DEVICES.
3. NODE.JS IS A PLATFORM BUILT ON CHROME'S JAVASCRIPT
RUNTIME FOR EASILY BUILDING FAST, SCALABLE
NETWORK APPLICATIONS.
NODE.JS USES AN EVENT-DRIVEN, NON-BLOCKING
I/O MODELTHAT MAKES IT LIGHTWEIGHT AND EFFICIENT,
PERFECT FOR DATA-INTENSIVE REAL-TIME APPLICATIONS
THAT RUN ACROSS DISTRIBUTED DEVICES.
4. PLAN
1. Introduction
2. Event-driven programming
3. JS becomes now a normal language
4. JS becomes now a wonderful language for the web !
5. Drawbacks
9. II. EVENT-DRIVEN PROGRAMMING
!
Single thread, multi-threading
Event-driven programming definition
Why JS is good choice to do event-driven programming ?
15. Flow determined by events
!
result = db.query(‘select * from facebook.users’)
f(result)
!
db.query(‘select * from facebook.users’, f)
!
EVENT-DRIVEN PROGRAMMING
DEFINITION
16. EVENT LOOP
Image copied from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/EventLoop
17. EVENT LOOP
Image copied from http://www.aaronstannard.com/post/2011/12/14/Intro-to-NodeJS-for-NET-Developers.aspx
18. EVENT LOOP
Image copied from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/EventLoop
2 interesting properties :
There is at most one event handler running at any given time.
Any event handler will run to completion without being interrupted.
19. WHY JS ?
• No mix of blocking and non-blocking IO
•
Closure : no need to pass context around.
• First-class function : pass function as argument
20. III. JS becomes now a normal language
• Interactive mode
• Launch script without passing by html
• Read file, connect to DB ...
21. IV. A wonderful language for the web !
• Static web server with several lines of code
• NPM
• Lot of modules to work with the web: cookie, tcp, parse
json ...
• Perfect match for client-side JS (ex: angularJS)
• Horizontal scale
22. V. Drawbacks
• Limited set of library : mp3, png ...
• Not hit 1.0 yet, still 0.10 (same as Hadoop with
version 0.23 ...)
• IDE, debugger ... very primitive
• Javascript inherent difficulties ?