Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Writing applications with node.js on the Micros...

Dariusz Parys
February 18, 2013

Writing applications with node.js on the Microsoft platform

A Brief overview how to code apps in node.js on the Microsoft platform

Dariusz Parys

February 18, 2013
Tweet

More Decks by Dariusz Parys

Other Decks in Programming

Transcript

  1. 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
  2. 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
  3. WHY NODE.JS • SERVER-SIDE JAVASCRIPT • GREAT COMMUNITY • FITS

    GOOD FOR CERTAIN SCENARIOS (FOR INSTANCE STREAMING)
  4. 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/');
  5. 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" }, ... }
  6. 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'); });
  7. TEMPLATING WITH JADE h1 Available music to play ul each

    musicFile in music li #{musicFile.name} audio(controls, src='#{musicFile.url}')
  8. 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();
  9. 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 ); })
  10. CREATING A VM C:\> azure vm create --help help: Create

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