vn-info meetup on node.js
DESCRIPTION
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 !TRANSCRIPT
VN-INFO meetup 16/07/2014 at Officience, Paris Son NGUYEN KIM (@nguyenkims)
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 MODEL THAT
MAKES IT LIGHTWEIGHT AND EFFICIENT, PERFECT FOR
DATA-INTENSIVE REAL-TIME APPLICATIONS THAT RUN
ACROSS DISTRIBUTED DEVICES.
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 MODEL THAT MAKES IT LIGHTWEIGHT AND EFFICIENT,
PERFECT FOR DATA-INTENSIVE REAL-TIME APPLICATIONS
THAT RUN ACROSS DISTRIBUTED DEVICES.
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
I. INTRODUCTION Motivation
History
Main concept
NODE.JS IS USED BY BIGGEST COMPANIES IN VARIOUS DOMAINS
MOTIVATION
HISTORY
• Created in 2009 by Ryan Dahl
• Sponsored by Joyent
Image copied from http://blog.newrelic.com/2012/07/11/recap-of-nodeconf-2012/
event-driven programming !
MAIN CONCEPT
Image copied from http://kunkle.org/nodejs-explained-pres/#/conceptually-simple
II. EVENT-DRIVEN PROGRAMMING !
Single thread, multi-threading Event-driven programming definition
Why JS is good choice to do event-driven programming ?
SINGLE-THREAD
I/O Read file
Main thread
SINGLE-THREAD
I/O Read file
Main thread
Blocking ...
MULTI-THREAD
I/O Read file
I/O Query DB
Main thread
Thread 1
Thread 2
MULTI-THREAD
I/O Read file
I/O Query DB
Main thread
Thread 1
Thread 2
Manage concurrency : lock everywhere !
Debug / Write / Test
EVENT-DRIVEN PROGRAMMING DEFINITION
Flow determined by events !
result = db.query(‘select * from facebook.users’) f(result)
!!
Flow determined by events !
result = db.query(‘select * from facebook.users’) f(result)
!db.query(‘select * from facebook.users’, f)
!
EVENT-DRIVEN PROGRAMMING DEFINITION
EVENT LOOPImage copied from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/EventLoop
EVENT LOOPImage copied from http://www.aaronstannard.com/post/2011/12/14/Intro-to-NodeJS-for-NET-Developers.aspx
EVENT LOOPImage 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.
WHY JS ?
• No mix of blocking and non-blocking IO
• Closure : no need to pass context around.
• First-class function : pass function as argument
III. JS becomes now a normal language
• Interactive mode
• Launch script without passing by html
• Read file, connect to DB ...
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
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 ?
THANKS YOU !