there's a new kid in town: node.js
TRANSCRIPT
![Page 1: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/1.jpg)
There's a new kid in town
and his name is
NodeJS
Mike Amundsen @mamund
![Page 2: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/2.jpg)
Setting the Stage
• Mike Amundsen
• Goals
• Non-Goals
• Bottom Line
![Page 3: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/3.jpg)
Mike Amundsen
• Presenter, Architect, Programmer • Current Focus: "Hypermedia" • Book Project ...
• Designing Hypermedia APIs
with HTML5 and NodeJS - O’Reilly, late 2011
![Page 4: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/4.jpg)
Goals
• Introduce NodeJS
• Talk about why NodeJS is "different" • See some NodeJS examples
• Encourage you to try it out yourself
![Page 5: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/5.jpg)
Non-Goals
• Details of downloading and installing NodeJS
• Defending NodeJS programming model • Learning Javascript • Writing modules or contributing to NodeJS
![Page 6: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/6.jpg)
Bottom Line
• NodeJS is not 'business as usual' • Javscript is not the interesting part of NodeJS
• NodeJS represents an emerging trend
• You should try it!
![Page 7: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/7.jpg)
WAIT...
![Page 8: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/8.jpg)
We spend a lot of our time waiting...
![Page 9: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/9.jpg)
WAIT...
![Page 10: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/10.jpg)
For someone else to do stuff...
![Page 11: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/11.jpg)
WAIT...
![Page 12: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/12.jpg)
So we can get our stuff done.
![Page 13: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/13.jpg)
WAIT...
![Page 14: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/14.jpg)
And that's a waste of valuable resources.
![Page 15: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/15.jpg)
And that's a bummer!
![Page 16: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/16.jpg)
I wonder, is there another way to do this?
![Page 17: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/17.jpg)
Ryan Dahl sez "Yes!"
![Page 18: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/18.jpg)
NodeJS
![Page 19: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/19.jpg)
Why NodeJS is Different
![Page 20: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/20.jpg)
Threads
• Most Web frameworks use "threads" to handle work
• One thread for each request • Multiple threads for concurrent execution
• There is a limit to the number of threads
• But as long as requests are short, it's not a problem
![Page 21: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/21.jpg)
It used to be pretty simple...
• Local files
• Local database
• Single data source
![Page 22: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/22.jpg)
But then along came the cloud...
• Remote files (Amazon S3) • Remote data (SQL Azure) • Multiple data sources (Twitter, Flickr, Disqus, etc.)
![Page 23: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/23.jpg)
All that stuff means more waiting...
![Page 24: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/24.jpg)
And that means longer requests...
![Page 25: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/25.jpg)
And that's a bummer!
![Page 26: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/26.jpg)
So NodeJS does it another way
• Scavenge the "wait states" as execution time
• Use a single loop (queue) 1. Execute a request 2. Go to the next item in the queue
3. Go to step 1
• No more waiting!
![Page 27: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/27.jpg)
It's called the Reactor Pattern
![Page 28: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/28.jpg)
This works great for the cloud because...
• Requests usually involve waiting
• Requests are usually "side-effect free" (state-less) • Most of the "work" is done by someone else (remote
servers)
![Page 29: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/29.jpg)
There, I fixed it!
![Page 30: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/30.jpg)
Wait a minute<g>; how do you code this?
![Page 31: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/31.jpg)
Getting started is easy...
• Starting a request is no problem
• But you need to be ready when the remote server is done
• You need to register a location for the returning call
![Page 32: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/32.jpg)
You need a "callback"
![Page 33: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/33.jpg)
If only there was a programming language that everyone already knew that also handled callbacks easily...
![Page 34: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/34.jpg)
Let's see...
• Scheme
• Erlang
• Scala
• C++
• ... • There's at least one more I know of...
![Page 35: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/35.jpg)
There, I fixed it again!
![Page 36: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/36.jpg)
Javascript is a logical choice for Node
• It's already well-known (if not well-understood<g>) • There are multiple JS "engines" (Node uses V8) • Javascript already supports callbacks and closures
![Page 37: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/37.jpg)
So, let's review...
![Page 38: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/38.jpg)
So, let's review...
NodeJS uses the Reactor Pattern (event loop) to take advantage of the extended wait-states that are now more common with cloud-based implementations.
![Page 39: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/39.jpg)
So, let's review...
NodeJS uses the Reactor Pattern (event loop) to take advantage of the extended wait-states that are now more common with cloud-based implementations. And NodeJS uses Javascript on the "front-end" because it supports callbacks/closures, is readily available, and well-known.
![Page 40: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/40.jpg)
Ok, let's see some code!
![Page 41: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/41.jpg)
NodeJS code is pretty straightforward
![Page 42: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/42.jpg)
NodeJS code is pretty straightforward
![Page 43: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/43.jpg)
Creating an HTTP file server is easy.
![Page 44: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/44.jpg)
Writing a file uploader is even easier.
![Page 45: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/45.jpg)
You can write clients w/ Node, too.
![Page 46: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/46.jpg)
NodeJS has a package system: npm
![Page 47: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/47.jpg)
Node Package Manager
![Page 48: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/48.jpg)
And lots of modules...
![Page 49: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/49.jpg)
For building full-featured applications
![Page 50: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/50.jpg)
Check out these resources...
![Page 51: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/51.jpg)
Home Page & Discussion Group
• NodeJS Site (http://nodejs.org) • Discussion Group
(https://groups.google.com/forum/#!forum/nodejs)
![Page 52: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/52.jpg)
Books & Tutorials
• Hands On NodeJS (Pedro Teixeira) • Up and Running w/ Node
(http://ofps.oreilly.com/titles/9781449398583/) • NodeTuts (http://nodetuts.com/)
![Page 53: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/53.jpg)
Online Hosting
• JSApp.US (http://jsapp.us/) - *instant*
• Joyent (https://api.no.de/) • Nodester (http://nodester.com/) • DotCloud (http://www.dotcloud.com/) • NodeSocket (http://www.nodesocket.com/) *nya*
• NodeJitsu (http://www.nodejitsu.com/#/home) *nya*
![Page 54: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/54.jpg)
In Summary...
![Page 55: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/55.jpg)
NodeJS
• Based on the "Reactor Pattern" • Uses Javascript on the front-end
• Is well-suited for cloud-based implementations
• Completely Open-Source (free) • Built on Linux • Windows Native port soon
• Represents a growing trend
![Page 56: There's a new kid in town: node.js](https://reader034.vdocuments.site/reader034/viewer/2022052523/5550b5b5b4c90504628b4b9f/html5/thumbnails/56.jpg)
There's a new kid in town
and his name is
NodeJS
Mike Amundsen @mamund