An Introduction to Node
From David Bella hosted by NYC Open Data
January 30, 2014
2

A Little About Me
• B.S. Computer Science from UCONN
• 2 Years of ETL in Finance (Perl)
• Attended The Flatiron School ...
3

INANE
I'm Not A Node Expert
4

What is Node?
Some confusing terminology

• Web Server?
• Engine?
• Runtime?
• Stack?
• Platform
5

What is Node?
False comparisons to other technology

• Rails - A Web Framework
• nginx - A Web Server
• JavaScript - A ...
6

What is Node?
What is Node Made Of?

• JavaScript - The Language
• V8 - The JavaScript Engine
• Abstraction Layer
• Cor...
7

JavaScript and V8
JavaScript engines were historically closely tied to browsers

V8 is the JavaScript engine pulled out...
8

Node and V8
Node uses the V8 Engine

Node's abstraction layer is an implementation of the Reactor Pattern

Node's core ...
9

The Reactor Pattern
The main event loop is non-blocking and waits for work requests

Requests are dispatched out to the...
10

Node, The Reactor, and You
ACTUAL SIZE
11

Node, The Reactor, and You
The code you run runs "normally"

Anything run through Node goes through the reactor

This ...
Example "Time"
13

Synchronous Timer
0 .v r s e p = r q i e " l e " ;
1 a le
eur(sep)
0 .s e p s e p
2 le.le(
0.
3
0.
4

1

0 .)
5 ;
0 .c...
14

Asynchronous Timer
0.
1
0 .s t i e u (
2 eTmot
0.
3
0.
4

fnto( {
u c i n ) },
10
00

0 .)
5 ;
0 .c n o e l g " O G G ...
15

Callbacks
16

Callbacks
There is nothing magical or Node specific about callbacks

It is simply a function passed into another funct...
Phoning in Some
Callbacks
18

Callbacks and Events
This is an example of what we mean when we say Node is Event Driven

Callbacks/Events are importa...
Node Doesn't Care
About You
20

Tying It All Together...
• Node uses V8 JavaScript
• Node implements an event-driven Reactor pattern
• JavaScript was ...
I Request an HTTP
Example
22

So - Why's It Good?
Highly concurrent - the event based architecture helps handle requests
without having to create ne...
23

And... Why's It Bad?
It's not a silver bullet for all issues

Not great at single threaded CPU intensive calculations
...
24

Short Note about NPM
NPM is the Node Package Maid Manager

Allows you to pull in extra packages for Node that you can ...
Half Time Review
and Questions
26

What We Are Making
A simple REST API powered by Express, backed by MongoDB

A front end with Backbone.js for rendering...
27

Questions and Thanks!
A huge thank you to:

• Vivian and NYC Open Data
• Ryan Dahl and Joyent for making and supportin...
Upcoming SlideShare
Loading in …5
×

An introduction to node3

1,483 views

Published on

Node.js introduction workshop given by David Bella
at NYC Open Data Meetup group

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,483
On SlideShare
0
From Embeds
0
Number of Embeds
596
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

An introduction to node3

  1. 1. An Introduction to Node From David Bella hosted by NYC Open Data January 30, 2014
  2. 2. 2 A Little About Me • B.S. Computer Science from UCONN • 2 Years of ETL in Finance (Perl) • Attended The Flatiron School Ruby 003 in September • Currently Software Engineer at XO Group (Rails) • Join us! XO Hackathon February 8th and 9th - bit.ly/xohack davidhenrybella davidbella davidbella.com
  3. 3. 3 INANE I'm Not A Node Expert
  4. 4. 4 What is Node? Some confusing terminology • Web Server? • Engine? • Runtime? • Stack? • Platform
  5. 5. 5 What is Node? False comparisons to other technology • Rails - A Web Framework • nginx - A Web Server • JavaScript - A Programming Language • Node - A Non-Blocking, Event-Driven, Networking Platform
  6. 6. 6 What is Node? What is Node Made Of? • JavaScript - The Language • V8 - The JavaScript Engine • Abstraction Layer • Core Library These 3-4 items make up what we know as "Node"
  7. 7. 7 JavaScript and V8 JavaScript engines were historically closely tied to browsers V8 is the JavaScript engine pulled out of the browser (Chrome) Now we can run JavaScript code like we run Ruby, Perl, Python... One might say JS is to V8 as Ruby is to MRI, maybe
  8. 8. 8 Node and V8 Node uses the V8 Engine Node's abstraction layer is an implementation of the Reactor Pattern Node's core library makes use of the reactor pattern to handle requests Ruby's EventMachine is an implementation of the reactor pattern
  9. 9. 9 The Reactor Pattern The main event loop is non-blocking and waits for work requests Requests are dispatched out to the reactor by the event loop The reactor is a single threaded worker that takes work requests, processes them one at a time until fully completed, then starts the next request
  10. 10. 10 Node, The Reactor, and You ACTUAL SIZE
  11. 11. 11 Node, The Reactor, and You The code you run runs "normally" Anything run through Node goes through the reactor This up environment an you asynchronous sets interact that can with
  12. 12. Example "Time"
  13. 13. 13 Synchronous Timer 0 .v r s e p = r q i e " l e " ; 1 a le eur(sep) 0 .s e p s e p 2 le.le( 0. 3 0. 4 1 0 .) 5 ; 0 .c n o e l g " O N N " ; 6 osl.o(N O O)
  14. 14. 14 Asynchronous Timer 0. 1 0 .s t i e u ( 2 eTmot 0. 3 0. 4 fnto( { u c i n ) }, 10 00 0 .) 5 ; 0 .c n o e l g " O G G " ; 6 osl.o(G O O)
  15. 15. 15 Callbacks
  16. 16. 16 Callbacks There is nothing magical or Node specific about callbacks It is simply a function passed into another function that gets executed at some point - usually when that second function is finished or has something to report to the caller, like an error
  17. 17. Phoning in Some Callbacks
  18. 18. 18 Callbacks and Events This is an example of what we mean when we say Node is Event Driven Callbacks/Events are important in Node so that we know when Node is done running whatever work we gave it Node can alert us of an event by using a callback
  19. 19. Node Doesn't Care About You
  20. 20. 20 Tying It All Together... • Node uses V8 JavaScript • Node implements an event-driven Reactor pattern • JavaScript was designed as an event based programming language Wonderful! Node ties together two beautiful concepts - evented programming and an event based pattern. so much. wow.
  21. 21. I Request an HTTP Example
  22. 22. 22 So - Why's It Good? Highly concurrent - the event based architecture helps handle requests without having to create new threads and switch between them Real time, two way connections - Create a richer web experience for the user (we'll get to this much later) Open Web Stack - HTML, CSS, JS are a dream team, now we have JS on the backend, further reducing complexity
  23. 23. 23 And... Why's It Bad? It's not a silver bullet for all issues Not great at single threaded CPU intensive calculations While it is JavaScript, the evented, asynchronous environment is difficult to get used to
  24. 24. 24 Short Note about NPM NPM is the Node Package Maid Manager Allows you to pull in extra packages for Node that you can then require • npm install -g <package_name> # Installs globally • npm install <package_name> # Installs locally
  25. 25. Half Time Review and Questions
  26. 26. 26 What We Are Making A simple REST API powered by Express, backed by MongoDB A front end with Backbone.js for rendering the collection Simple publish subscribe functionality with Faye to provide live updates
  27. 27. 27 Questions and Thanks! A huge thank you to: • Vivian and NYC Open Data • Ryan Dahl and Joyent for making and supporting Node • Vadim Makeev for the Shower presentation software • Everyone here! • XO Group for employing me!

×