Getting started with developing Nodejs

124
node.js yet another talk on getting started @philhawksworth

description

An introduction to developing with Node.js and some useful tools to help the development and deployment processes. This talk was given at Asyncjs in Brightonhttp://asyncjs.com/intro-nodejs

Transcript of Getting started with developing Nodejs

Page 1: Getting started with developing Nodejs

node.jsyet another talk on

getting started

@philhawksworth

Page 2: Getting started with developing Nodejs

what we’ll look atwhaddizit?

installation optionshello world

modules & frameworksdeploying & hostingcomet and beyond

Page 3: Getting started with developing Nodejs

assumptions

web development experiencejavascript knowledge

unix, linux, osxnot a nodejs ninja

Page 4: Getting started with developing Nodejs

whaddizit?

Page 5: Getting started with developing Nodejs

Evented I/O forV8 Javascript

Page 6: Getting started with developing Nodejs

c++v8 javascript engine

server-side javascriptsingle event loop

non-blocking

evented i-what now?

Page 7: Getting started with developing Nodejs

strong javascriptjQuery patterns

useful knowledge

Page 8: Getting started with developing Nodejs

jQuery patternsdangerous knowledge

Page 9: Getting started with developing Nodejs

considerationshow mature is it?

v0.0.1: early 2009, currently v.0.4.8

who uses it?everyone is playing.

Page 10: Getting started with developing Nodejs
Page 11: Getting started with developing Nodejs
Page 12: Getting started with developing Nodejs

considerationshow mature is it?

v0.0.1: early 2009, currently v.0.4.8

who uses it?everyone is playing.

should I be scared of it?no. but be cautious.

Page 13: Getting started with developing Nodejs

ball-ache:stability

rate of change

Page 14: Getting started with developing Nodejs

installation options

build from sourcepackage

ndistron

Page 15: Getting started with developing Nodejs

from sourceclone source from github

install dependanciesxcode tools

configure, make, make install

Page 16: Getting started with developing Nodejs

package

Page 17: Getting started with developing Nodejs
Page 18: Getting started with developing Nodejs

ball-ache:stability

rate of change

Page 19: Getting started with developing Nodejs

many versionsmany versionsmany versionsmany versionsmany versionsndistro & n

Page 20: Getting started with developing Nodejs

ndistro node distribution toolkit

Page 21: Getting started with developing Nodejs

enables many versions of node

Page 22: Getting started with developing Nodejs

http://github.com/visionmedia/ndistro

Page 23: Getting started with developing Nodejs

http://github.com/visionmedia/ndistro

Page 24: Getting started with developing Nodejs
Page 25: Getting started with developing Nodejs
Page 26: Getting started with developing Nodejs
Page 27: Getting started with developing Nodejs
Page 28: Getting started with developing Nodejs
Page 29: Getting started with developing Nodejs
Page 30: Getting started with developing Nodejs
Page 31: Getting started with developing Nodejs

local versions for each project

Page 32: Getting started with developing Nodejs

n

Page 33: Getting started with developing Nodejs

install as a module

Page 34: Getting started with developing Nodejs

ball-acheversion stabilitymodule stability

Page 35: Getting started with developing Nodejs

installing modules

npmnode package manager

Page 36: Getting started with developing Nodejs

curl http://npmjs.org/install.sh | sh

Page 37: Getting started with developing Nodejs
Page 38: Getting started with developing Nodejs

$ npm install <package>

Page 39: Getting started with developing Nodejs

$ npm install n

Page 41: Getting started with developing Nodejs

$ npm ls

Page 44: Getting started with developing Nodejs

$ npm update n

Page 45: Getting started with developing Nodejs

$ npm install n

Page 46: Getting started with developing Nodejs

$ npm update npm

Page 47: Getting started with developing Nodejs

n

Page 48: Getting started with developing Nodejs

while ndistro is for virtual

environments

Page 49: Getting started with developing Nodejs

while ndistro is for local

environments

Page 50: Getting started with developing Nodejs

n gives system wide

node versioning

Page 51: Getting started with developing Nodejs

$ n 0.2.6$ n v0.3.3

Page 52: Getting started with developing Nodejs

downloadconfigure

make install

Page 53: Getting started with developing Nodejs
Page 54: Getting started with developing Nodejs

$ n ls

Page 55: Getting started with developing Nodejs

$ n

Page 56: Getting started with developing Nodejs

0.2.3 0.2.6 --debug 0.3.4 0.3.5ο 0.4.8

Page 57: Getting started with developing Nodejs

$ n use 0.4.8

Page 58: Getting started with developing Nodejs

what we’ll look atwhaddizit?

installation optionshello world

modules & frameworksdeploying & hostingcomet and beyond

Page 59: Getting started with developing Nodejs

hello world

Page 60: Getting started with developing Nodejs

hello world

app.js

Page 61: Getting started with developing Nodejs

$ node app.js

Page 62: Getting started with developing Nodejs

$ ./bin/node app.js

Page 63: Getting started with developing Nodejs

$ n use 0.4.8 app.js

Page 64: Getting started with developing Nodejs
Page 65: Getting started with developing Nodejs

frameworksget a little help

uri routingcontent negotiation

templatingenvironment configuration

Page 66: Getting started with developing Nodejs

expressthe canonical web

development frameworkhttp://expressjs.com

Page 67: Getting started with developing Nodejs
Page 68: Getting started with developing Nodejs
Page 69: Getting started with developing Nodejs
Page 71: Getting started with developing Nodejs
Page 72: Getting started with developing Nodejs
Page 73: Getting started with developing Nodejs

bootstrappingquick scaffolding

Page 74: Getting started with developing Nodejs

$ express --template --css --session

Page 75: Getting started with developing Nodejs
Page 76: Getting started with developing Nodejs

$ n use 0.4.8 app.js

Page 77: Getting started with developing Nodejs
Page 78: Getting started with developing Nodejs
Page 79: Getting started with developing Nodejs
Page 80: Getting started with developing Nodejs

deployingwhere do I put this thing?

self-managedamazon, linode, slicehost

managedheroku, no.de

Page 81: Getting started with developing Nodejs
Page 82: Getting started with developing Nodejs
Page 83: Getting started with developing Nodejs
Page 84: Getting started with developing Nodejs
Page 85: Getting started with developing Nodejs

automated, git-based deployment

install via npm

manage dependancies via npm

limited versions of nodejs

duostack

Page 86: Getting started with developing Nodejs

hello world

server.js

Page 87: Getting started with developing Nodejs

$ git init$ git add$ git commit -m ‘1st commit’

Page 88: Getting started with developing Nodejs

$ duostack create nodedemo$ git push duostack master

Page 89: Getting started with developing Nodejs

Delta compression using up to 2 threads.Compressing objects: 100% (2/2), done.Writing objects: 100% (3/3), 416 bytes, done.Total 3 (delta 0), reused 0 (delta 0)

==== Duostack deploy received for nodedemo==== Compiling app... done Compressed size is 4.0KB==== Launching first instances.... done

==== App successfully deployed to==== http://nodedemo.duostack.net

Page 90: Getting started with developing Nodejs
Page 91: Getting started with developing Nodejs
Page 92: Getting started with developing Nodejs

self-managedamazon, linode, slicehost

Page 93: Getting started with developing Nodejs
Page 94: Getting started with developing Nodejs

deployingget it there

git

configure itinstall dependencies

get it up, and keep it upupstart

Page 95: Getting started with developing Nodejs

$ git clone project.git$ cd project$ ndistro

Page 96: Getting started with developing Nodejs

ndistro is really just the shell

Page 97: Getting started with developing Nodejs

replicates your environment

Page 98: Getting started with developing Nodejs

keeping it up

Page 99: Getting started with developing Nodejs

$ /etc/init.d/

Page 100: Getting started with developing Nodejs

http://upstart.ubuntu.com/

Page 101: Getting started with developing Nodejs
Page 102: Getting started with developing Nodejs
Page 103: Getting started with developing Nodejs

what we’ll look atwhaddizit?

installation optionshello world

modules & frameworksdeploying & hostingcomet and beyond

Page 104: Getting started with developing Nodejs

easy comet requests

websockets

Page 105: Getting started with developing Nodejs

cometlong-lived http requests

Page 106: Getting started with developing Nodejs
Page 107: Getting started with developing Nodejs
Page 108: Getting started with developing Nodejs
Page 109: Getting started with developing Nodejs
Page 110: Getting started with developing Nodejs

javascript on the clientasks, and listens

asks again, or takes action

Page 111: Getting started with developing Nodejs

websocketsmore efficient low latency comms

Page 112: Getting started with developing Nodejs

supported in modern browsers

Page 113: Getting started with developing Nodejs
Page 114: Getting started with developing Nodejs

Graceful degradation

Page 115: Getting started with developing Nodejs

WebSocketAdobe Flash Socket

Ajax long pollingAjax multipart streaming

Forever IframeJSONP Polling

Page 116: Getting started with developing Nodejs
Page 117: Getting started with developing Nodejs
Page 118: Getting started with developing Nodejs

but...node is not just for realtime

Page 119: Getting started with developing Nodejs

staying in the loop

and finding out more

Page 120: Getting started with developing Nodejs

github wikigithub.com/joyent/node/wiki

Page 122: Getting started with developing Nodejs

github wiki

Page 123: Getting started with developing Nodejs

@ryah@tjholowaychuk

@isaacs@sh1mmer