Slide 1

Slide 1 text

An Introduction

Slide 2

Slide 2 text

Hi I'm Simon Wood @hpoom http://about.me/hpoom

Slide 3

Slide 3 text

What is Node.js? 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. nodejs.org

Slide 4

Slide 4 text

History & Details Node.js was created by Ryan Dahl starting in 2009 Node.js is a packaged compilation of Google's V8 JavaScript engine and a core library, which is itself primarily written in JavaScript Current stable version is 0.10.6

Slide 5

Slide 5 text

Why Javascript server side? Can use the same language you're using for client side app. One language deployed everywhere Lets us share code between the browser and the backend It is event-based so it's like Ajax only server side It has low resource overheads It's fast. Really fast!

Slide 6

Slide 6 text

How to install it Using homebrew: brew install node Using macports: port install nodejs or install it from a compiled package

Slide 7

Slide 7 text

First Node.js test test.js console.log( 'Hello World!' ); terminal /node-demos$ node test.js Hello World! /node-demos$

Slide 8

Slide 8 text

HTTP Hello World hello.js var http = require( 'http' ); var server = http.createServer(); server.on( 'request', function( req, res ) { res.end( 'Hello World!' ); } ); server.listen( 1337, '127.0.0.1' ); console.log( 'Server running at http://127.0.0.1:1337' ); terminal /node-demos$ node hello.js Server running at http://127.0.0.1:1337

Slide 9

Slide 9 text

HTTP Hello World

Slide 10

Slide 10 text

Event driven jQuery - Client Side $( 'button' ).on( 'click', function( event ) { document.write( 'Event driven' ); } ); Node.js - Server Side server.on( 'request', function( req, res ) { res.write( 'Event driven' ); } );

Slide 11

Slide 11 text

Non-blocking I/O Blocking I/O var post = db.query( 'select * from posts where id = 1' ); doSomethingWithPost( post ); doSomethingElse(); Non-blocking I/O callback = function( post ) { doSomethingWithPost( post ) } db.query(' select * from posts where id = 1', callback ); doSomethingElse();

Slide 12

Slide 12 text

What's supported HTTP TCP Sockets File I/O Many DB connectors MySQL, Redis, MongoDB, and more...

Slide 13

Slide 13 text

Packages & Extensions Packages written in Javascript Either small packages of tools code, frameworks, or libraries for talking to DB's etc Packages best managed with NPM Extensions written in C++ Used to extend the core functions available to Node.js Commonly used to write libraries for DB's etc

Slide 14

Slide 14 text

What Node.js is good for? Long polling Keeping lots of concurrent connections open Having same code server and client side Networking operations Real time applications Great for chat applications, polling applications like gmail, games servers, API's, API Gateways, proxy servers

Slide 15

Slide 15 text

When not to use Node.js Still use traditional languages like PHP, Python, Ruby for tradition web solutions You would not rewrite wordpress in Node.js It could do it, but it is not the best choice

Slide 16

Slide 16 text

Who is using Node.js LinkedIn Ebay Microsoft Uber Yahoo Holiday Extras nodejs.org/industry

Slide 17

Slide 17 text

Questions?