Slide 1

Slide 1 text

Node.js, toy or power tool? Jacksonville Code Camp, 2012 Ovidiu Dimulescu @odimulescu speakerdeck.com/odimulescu

Slide 2

Slide 2 text

• What problem? • How’s Node.js helping? • Use cases • Industry support • Coding in Node.js • Ecosystem • Questions ? Agenda

Slide 3

Slide 3 text

About @odimulescu • Working on the Web since 1997 • • Organizer for JaxMUG.com • Co-Organizer for Jax Big Data meetup

Slide 4

Slide 4 text

Node.js - What’s the problem? Fast CPUs Spinning wheels How do we saturate the CPU doing useful work?

Slide 5

Slide 5 text

Node.js - How’s it helping? • Uses event-driven, non-blocking IO • Enforces async throughout*

Slide 6

Slide 6 text

Multi-Threaded Servers *Credit: blog.cloudfoundry.com

Slide 7

Slide 7 text

Node.js - Single Thread, Event-ed *Credit: blog.cloudfoundry.com

Slide 8

Slide 8 text

Node.js - Concurrency Node.js Event Loop Rq1 Rq2 Rq1 Rq2 Green - Request Executing Red - IO wait

Slide 9

Slide 9 text

Node.js - Concurrency Higher Concurrency Same Latency Thread Node.js

Slide 10

Slide 10 text

Node.js - Been there, done that Event Machines • - Twisted • - EventMachine • - Mina, Netty, Atmosphere, vertx.io • - POE Others • Erlang • Scala / Akka

Slide 11

Slide 11 text

Node.js - But ... They mix async with sync and the mentality is towards sync in libraries, drivers etc.

Slide 12

Slide 12 text

• Proxy between different data layers • Soft real-time apps • Crawlers • CLI tools • Quick prototyping • Lower HW and Operational cost* Node.js - Use Cases

Slide 13

Slide 13 text

• Culture mismatch • Uses Javascript • Requests are CPU intensive • Apps relies on specific libraries / functionality • Transactional systems Node.js - Not best fit

Slide 14

Slide 14 text

Node.js - Industry Support

Slide 15

Slide 15 text

Node.js - Industry Usage

Slide 16

Slide 16 text

1. Go to nodejs.org 2. Download and run installer Node.js - Installation

Slide 17

Slide 17 text

1. Go to nodejs.org 2. Download and run installer What’s included? node - binary npm - cli package manager built-in support for http, net, dns Node.js - Installation

Slide 18

Slide 18 text

1. Regular Installation 2. Make it a service Windows - NSSM, srvany, etc. Unix - Distro dependent 3. Front-end WS Integration IIS 7+ Integration - iisnode Apache - mod_proxy or mod_rewrite Nginx - rewrite or proxy HAProxy, stunnel Node.js - Server Installation

Slide 19

Slide 19 text

Lowest privileges Unix: drop to non-root via setuid / setguid Front with a secure Proxy Enable safeguards “use strict” Node.js - Considerations

Slide 20

Slide 20 text

CLI Version - helloworld.js console.log(“Hello world”); $ node helloworld.js Hello World Web Version Node.js - Hello World

Slide 21

Slide 21 text

Web - Router Version Node.js - Hello World

Slide 22

Slide 22 text

Node.js - I will call you back

Slide 23

Slide 23 text

Node.js - When, then

Slide 24

Slide 24 text

Serial independent Runs a series of functions one after the previous function completed Serial dependent Runs a series of functions passing previous results into next function Parallel fashion Runs a series of function in parallel Queue Runs a series of function in parallel up to desired concurrency Library Choices Async, Groupie, Step, Q, etc. Node.js - Flow libraries

Slide 25

Slide 25 text

Module - mymodule.js Node.js - Modules Client mymodule_client.js

Slide 26

Slide 26 text

Node.js - Modules require(‘mylib’) - Lookup order 1. package.json -> ./lib/mylib.js 2. index.js 3. index.node package.json

Slide 27

Slide 27 text

• console • log4js • Winston • GELF - Graylog Extended Log Format • Windows Event Log ... Node.js - Logging

Slide 28

Slide 28 text

$ npm install node-inspector $ node --debug-brk myapp.js $ node --debug myapp.js debugger listening on port 5858 $ node-inspector visit http://0.0.0.0:8080/debug?port=5858 to start debugging Debuggers WebKit based: Chrome Eclipse V8 Debugger Plugin, JetBrains WebStorm Other Tools v8-profiler, node-profiler nodetime.com Node.js - Debugging

Slide 29

Slide 29 text

Node.js - Inspector

Slide 30

Slide 30 text

Node.js - Debugging

Slide 31

Slide 31 text

Database Drivers MS SQL, MongoDB, PostgreSQL, MySQL, Oracle, SQLite, Redis, CouchDB, Hive, Riak, Cassandra ORMs sequelize, persist, LazyBoy, Model, jugglingdb, node-orm Transactions, Connection Pooling node-mysql-queues Node.js - DB / ORM

Slide 32

Slide 32 text

• Derby • Express • Flatiron • Meteor • Mojito • Tower ... Browserify - Node to Browser conversion Node.js - Web frameworks

Slide 33

Slide 33 text

• assert - built in • API Easy • Cucumber • httpmock, nock, mockery • NodeUnit • Soda ... Node.js - Testing frameworks

Slide 34

Slide 34 text

Node.js - Scaling out

Slide 35

Slide 35 text

Node.js - Scaling out *Credit: blog.evantahler.com

Slide 36

Slide 36 text

• Reuse existing JavaScript skill and code • Low resource usage • Performant VM (Google’s V8) • Active Community, Lots of resources • Package Manager • Enforces Async across • Quick Prototyping • Growing Industry support Node.js - Wrapping up

Slide 37

Slide 37 text

Questions ? Ovidiu Dimulescu @odimulescu speakerdeck.com/odimulescu