Slide 1

Slide 1 text

node.js server of many uses Mike Brevoort Colorado Springs Open Source Users Group 23 February 2012 1

Slide 2

Slide 2 text

Mike Brevoort @mbrevoort work at... (though opinions expressed in this presentation are my own and not meant to represent Pearson) 2

Slide 3

Slide 3 text

agenda very brief intro to node.js a tour of some “unconventional” uses of node.js * though I don’t particularly like the work conventional 3

Slide 4

Slide 4 text

node.js An Evented I/O network server for Javascript created by Ryan Dahl sponsored by 4

Slide 5

Slide 5 text

“Most languages were designed to solve computational problems, but Node.js is different. Node.js was designed from the ground up to efficiently handle the communication that is at the heart of modern web applications.” http://www.joyentcloud.com/products/smart-appliances/ node-js-smartmachine/ 5

Slide 6

Slide 6 text

generating load 6

Slide 7

Slide 7 text

“Mozilla uses a single node thread to simulate 180K users! I have commercial testing gear that can't do that! #nodesummit” Chris Johnson @mast3rof0 - 1/24/2012 7

Slide 8

Slide 8 text

https://gist.github.com/1861747 8

Slide 9

Slide 9 text

9

Slide 10

Slide 10 text

interprocess RPC 10

Slide 11

Slide 11 text

DNode symmetric remote function calling between processes to/from the browser via socket.io JSON protocol dnode ports in ruby, java, php, perl https://github.com/substack/dnode async rpc through sockets/JSON 11

Slide 12

Slide 12 text

server client 12

Slide 13

Slide 13 text

headless testing 13

Slide 14

Slide 14 text

zombie.js fast headless simulated browser testing emulation 14

Slide 15

Slide 15 text

zombie.js fast headless simulated browser testing Cookies and Web Storage XMLHttpRequest in all its glory setTimeout/ setInterval pushState, popstate and hashchange events alert, confirm and prompt HTML5 parsing and dealing with tag soups DOM Level 3 implementation HTML5 form fields (search, url, etc) CSS3 Selectors with some extensions 15

Slide 16

Slide 16 text

headless WebKit with JavaScript API Fast and native NOT node.js But node is commonly used as an orchestrator 16

Slide 17

Slide 17 text

phantomjs-node “...implements a nauseously clever bridge between Phantom and Node” 17

Slide 18

Slide 18 text

screenshotting 18

Slide 19

Slide 19 text

curl http://localhost:3000/cnn.com > cnn.png https://github.com/visionmedia/screenshot-app screenshot-app web screenshotting 19

Slide 20

Slide 20 text

webcrawling 20

Slide 21

Slide 21 text

21

Slide 22

Slide 22 text

22

Slide 23

Slide 23 text

browser APIs or fallbacks 23

Slide 24

Slide 24 text

node-canvas https://github.com/LearnBoost/node-canvas HTML5 server-side canvas API fallback run canvas API calls in node, send an image back to the client great for some mobile use cases legacy browser fallback 24

Slide 25

Slide 25 text

Deployments 25

Slide 26

Slide 26 text

https://github.com/substack/propagit multi-server git deployment over http Propagit Hub drone drone drone drone git push http://hubhost:6001/ somerepo master repos/somerepo.git repos/somerepo.git repos/somerepo.git repos/somerepo.git 26

Slide 27

Slide 27 text

Propagit https://github.com/substack/propagit multi-server git deployment over http Hub drone drone drone drone propagit deploy --hub=hubhost:6000 --secret=beepboop \ somerepo ed56c6e85731d412fe22cf437cb63130afc34b07 deploy/ somerepo.ed56c... deploy/ somerepo.ed56c... deploy/ somerepo.ed56c... deploy/ somerepo.ed56c... 27

Slide 28

Slide 28 text

Propagit https://github.com/substack/propagit multi-server git deployment over http Hub drone drone drone drone propagit spawn --hub=hubhost:6000 --secret=beepboop \ somerepo ed56c6e85731d412fe22cf437cb63130afc34b07 \ -- node server.js 8085 deploy/ somerepo.ed56c... deploy/ somerepo.ed56c... deploy/ somerepo.ed56c... deploy/ somerepo.ed56c... 28

Slide 29

Slide 29 text

load balancing 29

Slide 30

Slide 30 text

Bouncy programmatic http load balancer and router https://github.com/substack/bouncy 30

Slide 31

Slide 31 text

Bouncy programmatic http load balancer and router https://github.com/substack/bouncy 31

Slide 32

Slide 32 text

network tracing 32

Slide 33

Slide 33 text

node_pcap decode, print and analyze packets node makes it very nice since each packet is emitted as a Buffer by the EventEmitter libpcap bindings https://github.com/mranney/node_pcap 33

Slide 34

Slide 34 text

shell scripting 34

Slide 35

Slide 35 text

shell scripting fs core library - abstract OS or shell implementation details can leverage the node module ecosystem great if you need to do I/O beyond filesystem npm client 35

Slide 36

Slide 36 text

fs.watch(filename, [options], listener) 36

Slide 37

Slide 37 text

https://github.com/polotek/procstreams pipe-able and composable shell scripting in node Procstreams 37

Slide 38

Slide 38 text

Browser fallbacks Deployment Load balancing Network tracing Shell scripting Load generation IPC Testing Screenshotting Webcrawling tip of the iceberg 38

Slide 39

Slide 39 text

@mbrevoort Mike Brevoort Thanks! Questions? 39