Transcript
Page 1: There's a new kid in town: node.js

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

Setting the Stage

• Mike Amundsen

• Goals

• Non-Goals

• Bottom Line

Page 3: There's a new kid in town: node.js

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

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

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

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

WAIT...

Page 8: There's a new kid in town: node.js

We spend a lot of our time waiting...

Page 9: There's a new kid in town: node.js

WAIT...

Page 10: There's a new kid in town: node.js

For someone else to do stuff...

Page 11: There's a new kid in town: node.js

WAIT...

Page 12: There's a new kid in town: node.js

So we can get our stuff done.

Page 13: There's a new kid in town: node.js

WAIT...

Page 14: There's a new kid in town: node.js

And that's a waste of valuable resources.

Page 15: There's a new kid in town: node.js

And that's a bummer!

Page 16: There's a new kid in town: node.js

I wonder, is there another way to do this?

Page 17: There's a new kid in town: node.js

Ryan Dahl sez "Yes!"

Page 18: There's a new kid in town: node.js

NodeJS

Page 19: There's a new kid in town: node.js

Why NodeJS is Different

Page 20: There's a new kid in town: node.js

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

It used to be pretty simple...

• Local files

• Local database

• Single data source

Page 22: There's a new kid in town: node.js

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

All that stuff means more waiting...

Page 24: There's a new kid in town: node.js

And that means longer requests...

Page 25: There's a new kid in town: node.js

And that's a bummer!

Page 26: There's a new kid in town: node.js

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

It's called the Reactor Pattern

Page 28: There's a new kid in town: node.js

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

There, I fixed it!

Page 30: There's a new kid in town: node.js

Wait a minute<g>; how do you code this?

Page 31: There's a new kid in town: node.js

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

You need a "callback"

Page 33: There's a new kid in town: node.js

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

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

There, I fixed it again!

Page 36: There's a new kid in town: node.js

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

So, let's review...

Page 38: There's a new kid in town: node.js

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

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

Ok, let's see some code!

Page 41: There's a new kid in town: node.js

NodeJS code is pretty straightforward

Page 42: There's a new kid in town: node.js

NodeJS code is pretty straightforward

Page 43: There's a new kid in town: node.js

Creating an HTTP file server is easy.

Page 44: There's a new kid in town: node.js

Writing a file uploader is even easier.

Page 45: There's a new kid in town: node.js

You can write clients w/ Node, too.

Page 46: There's a new kid in town: node.js

NodeJS has a package system: npm

Page 47: There's a new kid in town: node.js

Node Package Manager

Page 48: There's a new kid in town: node.js

And lots of modules...

Page 49: There's a new kid in town: node.js

For building full-featured applications

Page 50: There's a new kid in town: node.js

Check out these resources...

Page 51: There's a new kid in town: node.js

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

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

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

In Summary...

Page 55: There's a new kid in town: node.js

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

There's a new kid in town

and his name is

NodeJS

Mike Amundsen @mamund