SlideShare a Scribd company logo
PLAYING WITH FIRE
  (ROCKET FUEL ACTUALLY)
    An introduction to node.js
Mike Hagedorn                  Anthony Broussard
   @mwhagedorn                      @quantumpotato
codemav.com/mwhagedorn          codemav.com/quantumpotato
mike@silverchairsolutions.com     anthony@chaione.com
IN THE BEGINNING...




    Server-side Javascript
IN THE BEGINNING...




    Server-side Javascript
          (it sucked)
SERVER-SIDE JAVASCRIPT




    •Netscape Livewire(1996)
    •Rhino(1997)
    •Several others since(like 50)
Y SO BAD?




•Slow Engines
•Javascript’s Perception (until recently)
•Much better alternatives
Y IZ BETTR NAO?




 Lots of Competition
 •SpiderMonkey
 •JavascriptCore
 •Chakra
                   Javascript is cool now!
WHAT IS NODE.JS?

•Created By Ryan Dahl
•Google’s V8 Engine (No DOM)
•Uses Nonblocking I/O
•Single Threaded
•A New Way To Build Scalable Network Platforms
WHY SHOULD YOU CARE?
                            •Its Fast
  > summary(node1$ttime)
      Min. 1st Qu.    Median      Mean   3rd Qu.     Max.
    0.0000   0.0000   1.0000    0.7437    1.0000 106.0000

  > summary(thin1$ttime)
     Min. 1st Qu. Median        Mean 3rd Qu.     Max.
    0.000   1.000   1.000      1.122   1.000   74.000

  > summary(narwhal1$ttime)
     Min. 1st Qu. Median     Mean 3rd Qu.        Max.
    15.00   22.00   23.00   23.74   24.00       88.00

  > summary(v8cgi1$ttime)
     Min. 1st Qu. Median        Mean 3rd Qu.     Max.
    12.00   13.00   13.00      14.49   18.00    39.00
WHY SHOULD YOU CARE?
•It can handle LOTS of concurrent transactions
WHY SHOULD YOU CARE?


  • Makes near real time things easy
  • Its small
  • Its Javascript
   •(Second most used language on Github)
WHO’S USING IT




Others:   http://doiop.com/rocket-node
HELLO WORLD
server.js
HELLO WORLD
server.js

 setTimeout(function(){
  console.log(“world”)
 },2000);
 console.log(“hello”);
HELLO WORLD
server.js

 setTimeout(function(){
  console.log(“world”)
 },2000);
 console.log(“hello”);




            $ node server.js
            hello
            world
HELLO WORLD
server.js

 setTimeout(function(){
  console.log(“world”)
 },2000);
 console.log(“hello”);
                               print(“hello”);
                               sleep(2000);
                               print(“world”);




            $ node server.js
            hello
            world
NON-BLOCKING I/O
 (asynchronous is the new black)
BLOCKING I/O

var a = db.query('SELECT A');
console.log('result a:', a);

var b = db.query('SELECT B');
console.log('result b:', b);

       Time = SUM(A, B)
NON-BLOCKING I/O

db.query('SELECT A', function(result) {
  console.log('result a:', result);
});

db.query('SELECT B', function(result) {
  console.log('result b:', result);
});

              Time = MAX(A, B)
SINGLE THREADED!
               You have to use callbacks!

db.query('SELECT A', function(result) {
    object.mySlowCall(result, function(){
        console.log(“my result”);
     })
});
WHY ISN’T EVERYONE USING
  NON-BLOCKING I/O?
  There are cultural and infrastructural
                  reasons
CULTURAL BIAS

We’re taught I/O with this:

puts(“Enter your name:”)
var name = gets()

We’re taught to demand input and do
       nothing until we have it.
CULTURAL BIAS

This code:
puts(“Enter your name:”)
var name = gets(function(name){
   puts(“Name: “)+name);
})

is rejected as TOO COMPLICATED
MISSING INFRASTRUCTURE
So why isn’t everyone using event loops?

Single threaded event loops require I/O to be non blocking

Most libraries are not.
OTHER APPROACHES?
•Twisted
•EventMachine
•Others
•Have lots of blocking libs to contend with
•From the start Node has never provided a blocking API
•Its a clean slate
•These approaches can be hard to use
JAVASCRIPT...

•Has had event loops from the beginning
•Anonymous functions, closures
•Single threaded
•The culture of Javascript embraces evented
programming
GREAT FOR

•Single Page Apps
•Realtime updates
•Processors/Crawlers
•Process Monitoring
•File Uploading
INSTALLING
OSX
 $ brew install node

Linux
$ git clone ....
 $ configure
 $ make

Windows
  Not Yet (version 0.6)
INSTALLING NPM



  •Node Package Manager
  •Similar to RubyGems, Python easy_install


$ curl http://npmjs.org/install.sh | sh
COMMON JS MODULES
hello.js

   exports.world = function(){
     return “Hello World”;
   }
main.js
 var hello = require(‘./hello’);
 var sys = require(‘sys’);
 sys.puts(hello.world());

   $ node main.js     #Hello World
EVENTS
 {EventEmitter} = require ‘events’
 emitter = new EventEmitter
 emitter.on ‘foo’, -> console.log ‘bar’
 emitter.emitusual new_monster event. And check out how much nicer our
      emitting the ‘foo’
         dependency graph has become!




http://pragprog.com/magazines/2011-08/content
       Imagine No Dependencies
         A lot of Node developers will tell you that attaching things to global rather
         than exports is a no-no. And if you’re packaging your code as a library, or trying
         to make your code reusable, then they’re right. But if you’re developing a
         standalone application, then go ahead and let yourself declare a few globals.
QUEUEING AN EVENT

function longFunction(){};
process.nextTick(longFunction);



Call longfunction on next time through event loop
EMITTING AN EVENT
var events = require('events');

var eventEmitter = new events.EventEmitter();

eventEmitter.on('someOccurence', function(message){
    console.log(message);
});

eventEmitter.emit('someOccurence', 'Something happened!');
MANAGING ASYNCHRONCITY
   A        B         C




         use async!
MANAGING ASYNCHRONCITY
        A                    B                        C

var operation = function(a_data, b_data, callback){
  async.series([
        function(as_callback),
        function(as_callback),
        function(err,results){ //[resulta, resultb]       }
        ]);
        }
MANAGING ASYNCHRONCITY
                 A
                                               C

                 B

var operation = function(a_data, b_data, callback){
  async.parallel([
        function(as_callback),
        function(as_callback),
        function(err,results){ //[resulta, resultb]   }
        ]);
        }
EXPRESS WEB FRAMEWORK

var app = express.createServer();

app.get('/', function(req, res){
    res.send('Hello World');
});

app.listen(3000);
COFFEESCRIPT
•“Little language that compiles to javascript”
•“It’s just javascript”
• More ruby-like
COFFEESCRIPT
  •“Little language that compiles to javascript”
  •“It’s just javascript”
  • More ruby-like
square = (x) -> x * x
COFFEESCRIPT
  •“Little language that compiles to javascript”
  •“It’s just javascript”
  • More ruby-like
square = (x) -> x * x

square = function(x){
   return x * x;
}
DEMO
QUESTIONS?
                  http://spkr8.com/t/8178



   Mike Hagedorn                Anthony Broussard
    @mwhagedorn                     @quantumpotato
mike@silverchairsolutions.com     anthony@chaione.com

More Related Content

What's hot

Node.js - Best practices
Node.js  - Best practicesNode.js  - Best practices
Node.js - Best practices
Felix Geisendörfer
 
The State of JavaScript
The State of JavaScriptThe State of JavaScript
The State of JavaScript
Domenic Denicola
 
A Gentle Introduction to Event Loops
A Gentle Introduction to Event LoopsA Gentle Introduction to Event Loops
A Gentle Introduction to Event Loops
deepfountainconsulting
 
Domains!
Domains!Domains!
RxJS 5 in Depth
RxJS 5 in DepthRxJS 5 in Depth
RxJS 5 in Depth
C4Media
 
Add Some Fun to Your Functional Programming With RXJS
Add Some Fun to Your Functional Programming With RXJSAdd Some Fun to Your Functional Programming With RXJS
Add Some Fun to Your Functional Programming With RXJS
Ryan Anklam
 
W3C HTML5 KIG-How to write low garbage real-time javascript
W3C HTML5 KIG-How to write low garbage real-time javascriptW3C HTML5 KIG-How to write low garbage real-time javascript
W3C HTML5 KIG-How to write low garbage real-time javascript
Changhwan Yi
 
Event loop
Event loopEvent loop
Event loop
codepitbull
 
Coroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in PractiseCoroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in Practise
Christian Melchior
 
Asynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time MessagingAsynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time Messaging
Steve Rhoades
 
Asynchronous programming patterns in Perl
Asynchronous programming patterns in PerlAsynchronous programming patterns in Perl
Asynchronous programming patterns in Perl
deepfountainconsulting
 
Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)
xSawyer
 
Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}.toster
 
You will learn RxJS in 2017
You will learn RxJS in 2017You will learn RxJS in 2017
You will learn RxJS in 2017
名辰 洪
 
React PHP: the NodeJS challenger
React PHP: the NodeJS challengerReact PHP: the NodeJS challenger
React PHP: the NodeJS challenger
vanphp
 
Будь первым
Будь первымБудь первым
Будь первым
FDConf
 
Go Concurrency
Go ConcurrencyGo Concurrency
Go ConcurrencyCloudflare
 
Perl: Coro asynchronous
Perl: Coro asynchronous Perl: Coro asynchronous
Perl: Coro asynchronous
Shmuel Fomberg
 
Full-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.jsFull-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.jsMichael Lehmann
 

What's hot (20)

Node.js - Best practices
Node.js  - Best practicesNode.js  - Best practices
Node.js - Best practices
 
The State of JavaScript
The State of JavaScriptThe State of JavaScript
The State of JavaScript
 
A Gentle Introduction to Event Loops
A Gentle Introduction to Event LoopsA Gentle Introduction to Event Loops
A Gentle Introduction to Event Loops
 
Domains!
Domains!Domains!
Domains!
 
RxJS 5 in Depth
RxJS 5 in DepthRxJS 5 in Depth
RxJS 5 in Depth
 
Add Some Fun to Your Functional Programming With RXJS
Add Some Fun to Your Functional Programming With RXJSAdd Some Fun to Your Functional Programming With RXJS
Add Some Fun to Your Functional Programming With RXJS
 
W3C HTML5 KIG-How to write low garbage real-time javascript
W3C HTML5 KIG-How to write low garbage real-time javascriptW3C HTML5 KIG-How to write low garbage real-time javascript
W3C HTML5 KIG-How to write low garbage real-time javascript
 
Event loop
Event loopEvent loop
Event loop
 
Coroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in PractiseCoroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in Practise
 
Asynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time MessagingAsynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time Messaging
 
Asynchronous programming patterns in Perl
Asynchronous programming patterns in PerlAsynchronous programming patterns in Perl
Asynchronous programming patterns in Perl
 
Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)
 
Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}
 
You will learn RxJS in 2017
You will learn RxJS in 2017You will learn RxJS in 2017
You will learn RxJS in 2017
 
React PHP: the NodeJS challenger
React PHP: the NodeJS challengerReact PHP: the NodeJS challenger
React PHP: the NodeJS challenger
 
Будь первым
Будь первымБудь первым
Будь первым
 
Go Concurrency
Go ConcurrencyGo Concurrency
Go Concurrency
 
Perl: Coro asynchronous
Perl: Coro asynchronous Perl: Coro asynchronous
Perl: Coro asynchronous
 
Full-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.jsFull-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.js
 
Ubic
UbicUbic
Ubic
 

Similar to Playing With Fire - An Introduction to Node.js

Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)
Felix Geisendörfer
 
Original slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talk
Aarti Parikh
 
Emerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonEmerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the Horizon
Alex Payne
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
NodeXperts
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
Ricardo Silva
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applicationsTom Croucher
 
Node.js - As a networking tool
Node.js - As a networking toolNode.js - As a networking tool
Node.js - As a networking tool
Felix Geisendörfer
 
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
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 
JavaScript Multithread or Single Thread.pptx
JavaScript Multithread or Single Thread.pptxJavaScript Multithread or Single Thread.pptx
JavaScript Multithread or Single Thread.pptx
RAHITNATH
 
Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM Mechanics
Azul Systems, Inc.
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
David Padbury
 
An opinionated intro to Node.js - devrupt hospitality hackathon
An opinionated intro to Node.js - devrupt hospitality hackathonAn opinionated intro to Node.js - devrupt hospitality hackathon
An opinionated intro to Node.js - devrupt hospitality hackathon
Luciano Mammino
 
Implementing new WebAPIs
Implementing new WebAPIsImplementing new WebAPIs
Implementing new WebAPIs
Julian Viereck
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.js
Chris Cowan
 
Node.js - async for the rest of us.
Node.js - async for the rest of us.Node.js - async for the rest of us.
Node.js - async for the rest of us.
Mike Brevoort
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous Javascript
Garrett Welson
 
Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016
Ben Lesh
 

Similar to Playing With Fire - An Introduction to Node.js (20)

Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)
 
Original slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talk
 
Emerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonEmerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the Horizon
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Node.js - As a networking tool
Node.js - As a networking toolNode.js - As a networking tool
Node.js - As a networking tool
 
Node.js
Node.jsNode.js
Node.js
 
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
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
JavaScript Multithread or Single Thread.pptx
JavaScript Multithread or Single Thread.pptxJavaScript Multithread or Single Thread.pptx
JavaScript Multithread or Single Thread.pptx
 
Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM Mechanics
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
An opinionated intro to Node.js - devrupt hospitality hackathon
An opinionated intro to Node.js - devrupt hospitality hackathonAn opinionated intro to Node.js - devrupt hospitality hackathon
An opinionated intro to Node.js - devrupt hospitality hackathon
 
Implementing New Web
Implementing New WebImplementing New Web
Implementing New Web
 
Implementing new WebAPIs
Implementing new WebAPIsImplementing new WebAPIs
Implementing new WebAPIs
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.js
 
Node.js - async for the rest of us.
Node.js - async for the rest of us.Node.js - async for the rest of us.
Node.js - async for the rest of us.
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous Javascript
 
Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016
 

More from Mike Hagedorn

Experienced Cloud Engineer Looking for New Roles
Experienced Cloud Engineer Looking for New RolesExperienced Cloud Engineer Looking for New Roles
Experienced Cloud Engineer Looking for New Roles
Mike Hagedorn
 
Hacking the Internet of Things
Hacking the Internet of ThingsHacking the Internet of Things
Hacking the Internet of Things
Mike Hagedorn
 
Using OpenStack With Fog
Using OpenStack With FogUsing OpenStack With Fog
Using OpenStack With Fog
Mike Hagedorn
 
Exploring the Internet of Things Using Ruby
Exploring the Internet of Things Using RubyExploring the Internet of Things Using Ruby
Exploring the Internet of Things Using Ruby
Mike Hagedorn
 
2011 a grape odyssey
2011   a grape odyssey2011   a grape odyssey
2011 a grape odyssey
Mike Hagedorn
 

More from Mike Hagedorn (6)

Experienced Cloud Engineer Looking for New Roles
Experienced Cloud Engineer Looking for New RolesExperienced Cloud Engineer Looking for New Roles
Experienced Cloud Engineer Looking for New Roles
 
Couchbase Talk
Couchbase TalkCouchbase Talk
Couchbase Talk
 
Hacking the Internet of Things
Hacking the Internet of ThingsHacking the Internet of Things
Hacking the Internet of Things
 
Using OpenStack With Fog
Using OpenStack With FogUsing OpenStack With Fog
Using OpenStack With Fog
 
Exploring the Internet of Things Using Ruby
Exploring the Internet of Things Using RubyExploring the Internet of Things Using Ruby
Exploring the Internet of Things Using Ruby
 
2011 a grape odyssey
2011   a grape odyssey2011   a grape odyssey
2011 a grape odyssey
 

Recently uploaded

Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
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
 
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
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
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
 
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
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
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
 
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
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 

Recently uploaded (20)

Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
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...
 
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...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
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
 
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...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
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
 
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
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 

Playing With Fire - An Introduction to Node.js

  • 1. PLAYING WITH FIRE (ROCKET FUEL ACTUALLY) An introduction to node.js
  • 2. Mike Hagedorn Anthony Broussard @mwhagedorn @quantumpotato codemav.com/mwhagedorn codemav.com/quantumpotato mike@silverchairsolutions.com anthony@chaione.com
  • 3. IN THE BEGINNING... Server-side Javascript
  • 4. IN THE BEGINNING... Server-side Javascript (it sucked)
  • 5. SERVER-SIDE JAVASCRIPT •Netscape Livewire(1996) •Rhino(1997) •Several others since(like 50)
  • 6. Y SO BAD? •Slow Engines •Javascript’s Perception (until recently) •Much better alternatives
  • 7. Y IZ BETTR NAO? Lots of Competition •SpiderMonkey •JavascriptCore •Chakra Javascript is cool now!
  • 8.
  • 9. WHAT IS NODE.JS? •Created By Ryan Dahl •Google’s V8 Engine (No DOM) •Uses Nonblocking I/O •Single Threaded •A New Way To Build Scalable Network Platforms
  • 10. WHY SHOULD YOU CARE? •Its Fast > summary(node1$ttime) Min. 1st Qu. Median Mean 3rd Qu. Max. 0.0000 0.0000 1.0000 0.7437 1.0000 106.0000 > summary(thin1$ttime) Min. 1st Qu. Median Mean 3rd Qu. Max. 0.000 1.000 1.000 1.122 1.000 74.000 > summary(narwhal1$ttime) Min. 1st Qu. Median Mean 3rd Qu. Max. 15.00 22.00 23.00 23.74 24.00 88.00 > summary(v8cgi1$ttime) Min. 1st Qu. Median Mean 3rd Qu. Max. 12.00 13.00 13.00 14.49 18.00 39.00
  • 11. WHY SHOULD YOU CARE? •It can handle LOTS of concurrent transactions
  • 12. WHY SHOULD YOU CARE? • Makes near real time things easy • Its small • Its Javascript •(Second most used language on Github)
  • 13. WHO’S USING IT Others: http://doiop.com/rocket-node
  • 15. HELLO WORLD server.js setTimeout(function(){ console.log(“world”) },2000); console.log(“hello”);
  • 16. HELLO WORLD server.js setTimeout(function(){ console.log(“world”) },2000); console.log(“hello”); $ node server.js hello world
  • 17. HELLO WORLD server.js setTimeout(function(){ console.log(“world”) },2000); console.log(“hello”); print(“hello”); sleep(2000); print(“world”); $ node server.js hello world
  • 18. NON-BLOCKING I/O (asynchronous is the new black)
  • 19. BLOCKING I/O var a = db.query('SELECT A'); console.log('result a:', a); var b = db.query('SELECT B'); console.log('result b:', b); Time = SUM(A, B)
  • 20. NON-BLOCKING I/O db.query('SELECT A', function(result) { console.log('result a:', result); }); db.query('SELECT B', function(result) { console.log('result b:', result); }); Time = MAX(A, B)
  • 21. SINGLE THREADED! You have to use callbacks! db.query('SELECT A', function(result) { object.mySlowCall(result, function(){ console.log(“my result”); }) });
  • 22. WHY ISN’T EVERYONE USING NON-BLOCKING I/O? There are cultural and infrastructural reasons
  • 23. CULTURAL BIAS We’re taught I/O with this: puts(“Enter your name:”) var name = gets() We’re taught to demand input and do nothing until we have it.
  • 24. CULTURAL BIAS This code: puts(“Enter your name:”) var name = gets(function(name){ puts(“Name: “)+name); }) is rejected as TOO COMPLICATED
  • 25. MISSING INFRASTRUCTURE So why isn’t everyone using event loops? Single threaded event loops require I/O to be non blocking Most libraries are not.
  • 26. OTHER APPROACHES? •Twisted •EventMachine •Others •Have lots of blocking libs to contend with •From the start Node has never provided a blocking API •Its a clean slate •These approaches can be hard to use
  • 27. JAVASCRIPT... •Has had event loops from the beginning •Anonymous functions, closures •Single threaded •The culture of Javascript embraces evented programming
  • 28. GREAT FOR •Single Page Apps •Realtime updates •Processors/Crawlers •Process Monitoring •File Uploading
  • 29. INSTALLING OSX $ brew install node Linux $ git clone .... $ configure $ make Windows Not Yet (version 0.6)
  • 30. INSTALLING NPM •Node Package Manager •Similar to RubyGems, Python easy_install $ curl http://npmjs.org/install.sh | sh
  • 31. COMMON JS MODULES hello.js exports.world = function(){ return “Hello World”; } main.js var hello = require(‘./hello’); var sys = require(‘sys’); sys.puts(hello.world()); $ node main.js #Hello World
  • 32. EVENTS {EventEmitter} = require ‘events’ emitter = new EventEmitter emitter.on ‘foo’, -> console.log ‘bar’ emitter.emitusual new_monster event. And check out how much nicer our emitting the ‘foo’ dependency graph has become! http://pragprog.com/magazines/2011-08/content Imagine No Dependencies A lot of Node developers will tell you that attaching things to global rather than exports is a no-no. And if you’re packaging your code as a library, or trying to make your code reusable, then they’re right. But if you’re developing a standalone application, then go ahead and let yourself declare a few globals.
  • 33. QUEUEING AN EVENT function longFunction(){}; process.nextTick(longFunction); Call longfunction on next time through event loop
  • 34. EMITTING AN EVENT var events = require('events'); var eventEmitter = new events.EventEmitter(); eventEmitter.on('someOccurence', function(message){ console.log(message); }); eventEmitter.emit('someOccurence', 'Something happened!');
  • 35. MANAGING ASYNCHRONCITY A B C use async!
  • 36. MANAGING ASYNCHRONCITY A B C var operation = function(a_data, b_data, callback){ async.series([ function(as_callback), function(as_callback), function(err,results){ //[resulta, resultb] } ]); }
  • 37. MANAGING ASYNCHRONCITY A C B var operation = function(a_data, b_data, callback){ async.parallel([ function(as_callback), function(as_callback), function(err,results){ //[resulta, resultb] } ]); }
  • 38. EXPRESS WEB FRAMEWORK var app = express.createServer(); app.get('/', function(req, res){ res.send('Hello World'); }); app.listen(3000);
  • 39. COFFEESCRIPT •“Little language that compiles to javascript” •“It’s just javascript” • More ruby-like
  • 40. COFFEESCRIPT •“Little language that compiles to javascript” •“It’s just javascript” • More ruby-like square = (x) -> x * x
  • 41. COFFEESCRIPT •“Little language that compiles to javascript” •“It’s just javascript” • More ruby-like square = (x) -> x * x square = function(x){ return x * x; }
  • 42. DEMO
  • 43. QUESTIONS? http://spkr8.com/t/8178 Mike Hagedorn Anthony Broussard @mwhagedorn @quantumpotato mike@silverchairsolutions.com anthony@chaione.com

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. lunch counter example\n\n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. npm doesnt run at all on win due to a lack of compatible child process forking\n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n