Slide 1

Slide 1 text

WRITING APPLICATIONS WITH NODE.JS ON THE MICROSOFT PLATFORM TECHNICAL EVANGELIST, MICROSOFT HTTP://KOUDER.NET – @WRITELINE – [email protected]

Slide 2

Slide 2 text

WHAT I‘LL COVER • BRIEF OVERVIEW ON NODE.JS • BASIC WORKFLOW ON WRITING NODE.JS APPS • CODE, TEST, DEPLOY • RUNNING NODE.JS ON A CUSTOM VM

Slide 3

Slide 3 text

WHAT IS NODE.JS? • A PROCESS HOSTING GOOGLE‘S JAVASCRIPT ENGINE V8 • SINGLE THREADED • CODE PATHS ARE MOSTLY ASYNCHRONOUS (IF NOT YOUR APP MAY SUCK) • OPEN SOURCE, MAINTAINED BY JOYENT

Slide 4

Slide 4 text

WHY NODE.JS • SERVER-SIDE JAVASCRIPT • GREAT COMMUNITY • FITS GOOD FOR CERTAIN SCENARIOS (FOR INSTANCE STREAMING)

Slide 5

Slide 5 text

GITHUB REPOSITORY LET‘S CREATE ONE FOR TODAY‘S DEMO

Slide 6

Slide 6 text

A SIMPLE WEB SERVER var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(1337, '127.0.0.1'); console.log('Server running at http://127.0.0.1:1337/');

Slide 7

Slide 7 text

MODULES exports.helloWorld = function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello from node.js'); }

Slide 8

Slide 8 text

INSTALLING MODULES & DEPENDENCIES npm install npm search director npm install director

Slide 9

Slide 9 text

PACKAGE.JSON & DEPENDENCIES { ... "dependencies" : { "director": ">=1.1.0", "jade": ">=0.28.1", "formidable": ">=1.0.11", "union": ">=0.3.6", "icecast": ">=1.1.0", "queuestream": ">=0.0.5", "azure": ">=0.6.10" }, ... }

Slide 10

Slide 10 text

ROUTING WITH DIRECTOR var http = require('http'), director = require('director'); http.createServer(function(req, res) { router.dispatch(req, res, function(err){ if (err) { res.writeHead(404); res.end(); }; }); }).listen(1337); router.get('/', function() { this.res.writeHead(200, { 'Content-Type': 'text/plain' }); this.res.end('Hello from node.js through director'); });

Slide 11

Slide 11 text

TEMPLATING WITH JADE h1 Available music to play ul each musicFile in music li #{musicFile.name} audio(controls, src='#{musicFile.url}')

Slide 12

Slide 12 text

INTEGRATING AZURE BLOB STORAGE npm install azure var azure = require('azure'); process.env.AZURE_STORAGE_ACCOUNT = "accountname"; process.env.AZURE_STORAGE_ACCESS_KEY = "accountkey"; var blobService = azure.createBlobService();

Slide 13

Slide 13 text

EVENT EMITTERS IN ACTION var form = formidable.IncomingForm(); form .on('field', function(field, value) { console.log(field, value); }) .on('file', function(field, file) { console.log("file type: " + file.type); console.log("file size: " + file.size / 1024 | 0 ); console.log("file path: " + file.path); }) .on('progress', function(rec, expected){ console.log('progress: ' + rec + " of " + expected); }) .parse(req, function(err, fields, files){ console.log('Parsed file upload' + err ); })

Slide 14

Slide 14 text

CREATING A VM C:\> azure vm create --help help: Create a new Azure VM help: help: Usage: vm create [password] help: help: Options: help: -h, --help output usage information help: -o, --community The is a community image help: -c, --connect connect to existing VMs help: -l, --location location of the data center help: -a, --affinity-group affinity group help: -u, --blob-url blob url for OS disk help: -z, --vm-size VM size [small] help: extrasmall, small, medium, large, extralarge help: -n, --vm-name VM name help: -e, --ssh [port] enable SSH [22] help: -t, --ssh-cert SSH certificate help: -r, --rdp [port] enable RDP [3389] help: -s, --subscription use the subscription id help: -w, --virtual-network-name virtual network name help: -b, --subnet-names comma-delimited subnet names help: -v, --verbose use verbose output help: --json use json output

Slide 15

Slide 15 text

SCALE WITH WINDOWS AZURE

Slide 16

Slide 16 text

No content