Slide 1

Slide 1 text

NODE.JS A hands-on introduction

Slide 2

Slide 2 text

LUC CASTERA • Full-stack software developer & entrepreneur • Electrical Engineering: UVA / Georgia Tech • I work at Intellum on TribeSocial • Co-founder of job509.com & visit509.com • luccastera.com

Slide 3

Slide 3 text

MEETUP GOALS • To build and develop a community of node.js experts in Miami that contribute to the global node.js ecosystem • “Learn and build together” • Example: the Seattle Ruby group

Slide 4

Slide 4 text

AGENDA • Introductions • Basic Intro to node.js • Pair Programming • Prize Ceremony

Slide 5

Slide 5 text

INTRODUCTIONS name
 profession
 node.js expertise (beginner, intermediate, advanced)
 why are you here? who do you want to win the world cup?

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

WHAT IS NODE.JS?

Slide 8

Slide 8 text

– nodejs.org “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.”

Slide 9

Slide 9 text

– nodejs.org “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.”

Slide 10

Slide 10 text

V8

Slide 11

Slide 11 text

SERVER SIDE JAVASCRIPT

Slide 12

Slide 12 text

– nodejs.org “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.”

Slide 13

Slide 13 text

LIBUV libuv is a multi-platform support library with a focus on asynchronous I/O.

Slide 14

Slide 14 text

CALLBACKS

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

– nodejs.org “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.”

Slide 17

Slide 17 text

TYPICAL BLOCKING SERVER

Slide 18

Slide 18 text

NON-BLOCKING SERVER

Slide 19

Slide 19 text

ADVANTAGES

Slide 20

Slide 20 text

– nodejs.org “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.”

Slide 21

Slide 21 text

C10K PROBLEM

Slide 22

Slide 22 text

– nodejs.org “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.”

Slide 23

Slide 23 text

NETWORKING LIBRARIES • net • query string • url • UDP • DNS • HTTP(S) • …

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

WHY USE NODE.JS?

Slide 26

Slide 26 text

– nodejs.org “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.”

Slide 27

Slide 27 text

– nodejs.org “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.”

Slide 28

Slide 28 text

– nodejs.org “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.”

Slide 29

Slide 29 text

JAVASCRIPT Low barrier to entry

Slide 30

Slide 30 text

JS EVERYWHERE Our stack: MongoDB, node.js, JSON, Backbone.js

Slide 31

Slide 31 text

STRONG COMMUNITY 80,000+ npm packages

Slide 32

Slide 32 text

MAC, LINUX, AND WINDOWS

Slide 33

Slide 33 text

SMALL & STABLE

Slide 34

Slide 34 text

WELL DOCUMENTED

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

HOW TO USE NODE.JS

Slide 37

Slide 37 text

INSTALLING NODE.JS

Slide 38

Slide 38 text

NPM npm install express

Slide 39

Slide 39 text

DEMO

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

HELLO WORLD

Slide 42

Slide 42 text

Beginner Intermediate Advanced 1. Install node.js 2. Write a program that prints ‘Hello Miami’ to the console 3. Write a web server that says ‘Hello Miami’ at the root URL http://localhost:3000/ 1. Write a web server that says ‘Hello Miami’ at the root URL http://localhost:3000/ 2. Use the cluster module to start a cluster of 4 servers serving the ‘Hello Miami’ app at http://localhost:3000/ 1. Use the cluster module to start a cluster of 4 servers serving the ‘Hello Miami’ app at http://localhost:3000/

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

FAVORITE MODULES • async - avoid callback hell • underscore - JavaScript++ / utility belt • express - small web application framework • connect - middleware framework • mocha - testing (server-side and in browser) • grunt - task runner • sinon - test spies, stubs, and mocks • gleak - global variable leak detection • kue - priority job queue backed by redis • mongoose - mongodb ORM

Slide 45

Slide 45 text

LESSONS LEARNED • calllback(err, data) • jshint is your friend (include in build process) • always use ‘return’ on callback • use streams when you should (.e.g mongoose) • move CPU intensive sections to separate process

Slide 46

Slide 46 text

DEPLOYING NODE • Process handling: fail and restart (upstart, monit) • Use multiple node processes (kue) • Use a load balancer (haproxy) • upstart ulimit gotcha • stunnel for SSH • lock down npm dependencies (or shrinkwrap)

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

PAIR PROGRAMMING Form teams

Slide 49

Slide 49 text

WORLD CUP FEVER! • Write a program that when passed the name of a country, prints out the list of players currently in their national football/soccer team along with their age and current club (comma delimited) • Usage: 
 roster Chile • Output:
 Claudio Bravo, 31, Barcelona
 Eugenio Mena, 28, Santos
 Mauricio Isla, 26, Juventus • Tip: Wikipedia pages URL: 
 http://en.wikipedia.org/wiki/Chile_national_football_team#Current_squad • If you are stuck and want a hint, ask me ;-)