Node.js on microsoft azure april 2014

1,378 views

Published on

Presented at DevIntesection / Anglebrackets 2014. In this session we showed how to code for the cloud with node.js and Windows Azure. We started with an introduction to the node.js Developer Center for Windows Azure, the Azure SDK for Java , and other tools and materials we’ve developed to make life easier for node developers. Included were lots of working examples showing tips and tricks for building, deploying, connecting, and maintaining node applications and multi-tier Web applications that access data, servers and services on Windows Azure.

Published in: Internet, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,378
On SlideShare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Node.js on microsoft azure april 2014

  1. 1. Node.js Development in the Cloud with Azure Brian Benz, Sr. Technical Evangelist Microsoft Open Technologies, Inc.
  2. 2. 2 http://www.anglebrackets.org Agenda  Azure  Node  Node on Azure  Web Sites  IaaS/PaaS  Examples  Q&A
  3. 3. Azure Flexible
  4. 4. Azure IaaS, PaaS, SaaS
  5. 5. Application Scenarios
  6. 6. 6 http://www.anglebrackets.org The Landscape - Node on Azure  Deployment  Web Sites  From Gallery  Via Source Deployment  IaaS / PaaS  Via Cloud Service deployment from Visual Studio  Deployment tools and source control: GitHub, TFS, FTP  Dev Tools  Azure Node SDK  Azure CLI  Microsoft Web Platform Installer  Microsoft Node Tools for Visual Studio
  7. 7. Intro to Node.js
  8. 8. 8 http://www.anglebrackets.org What is Node.js?  A JavaScript runtime environment  Server-side JavaScript  Compiled  Command line  JavaScript API for network and file system access  Designed for high concurrency  Events, not threads or processes  Never blocks, not even for I/O  Uses CommonJS framework syntax  Close to real OO
  9. 9. 9 http://www.anglebrackets.org Why Use Node.js ?  JavaScript on server-side and client-side  Event loop with a stack  Node.JS serves requests in an event loop  Large number of simultaneous requests.  Avoids Context Switching  Waiting for I/O or Synchronization operation to complete.  Node attaches JS callbacks to I/O requests  The “event driven” part  When the original IO is completed, a callback to the server completes the request.
  10. 10. 10 http://www.anglebrackets.org Speedy I/O With Events Threads Events Threads lock apps / threads One thread Listens for incoming requests Process from queue Multiple threads dependent on multiple processes State saved for each event Depends on context switching Not dependent on I/O or Synchronization
  11. 11. Setting up Node.js for Azure
  12. 12. 12 http://www.anglebrackets.org Download Node.js nodejs.org
  13. 13. 13 http://www.anglebrackets.org npm installer - www.npmjs.org
  14. 14. 14 http://www.anglebrackets.org Get the SDK - azure.microsoft.com/downloads
  15. 15. 15 http://www.anglebrackets.org Get the CLI - azure.microsoft.com/downloads
  16. 16. 16 http://www.anglebrackets.org Web Platform Installer – CLI and SDK
  17. 17. 17 http://www.anglebrackets.org Install Results
  18. 18. 18 http://www.anglebrackets.org Docs - azure.microsoft.com/documentation/
  19. 19. Node.js on Azure Web Sites
  20. 20. 20 http://www.anglebrackets.org Node.js on Azure Web Sites  Node Options in the Gallery  Local Git Repository
  21. 21. 21 http://www.anglebrackets.org Node.js from the Web Site Gallery
  22. 22. 22 http://www.anglebrackets.org New > Web Site > Quick Create > Name and Click
  23. 23. 23 http://www.anglebrackets.org
  24. 24. 24 http://www.anglebrackets.org Node.js from Local Git
  25. 25. 25 http://www.anglebrackets.org Get git - http://git-scm.com/downloads
  26. 26. 26 http://www.anglebrackets.org Setting up your Repository  git init  git add .  git commit -m “first commit"  git remote add azure <URL created >  git push azure master  <Password>
  27. 27. 27 http://www.anglebrackets.org Initial Deployment Counting objects: 3, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 408 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) remote: Updating branch 'master'. remote: Updating submodules.
  28. 28. 28 http://www.anglebrackets.org Submodules remote: Preparing deployment for commit id '8f69499edd'. remote: Generating deployment script. remote: Generating deployment script for node.js Web Site remote: Generated deployment script files remote: Running deployment command... remote: Handling node.js deployment. remote: KuduSync.NET from: 'D:homesiterepository' to: 'D:homesitewwwroot' remote: Deleting file: 'hostingstart.html' remote: Copying file: 'server.js'
  29. 29. 29 http://www.anglebrackets.org Updating your Repository  git add .  git commit -m “commit message"  git push azure master  <Password>
  30. 30. 30 http://www.anglebrackets.org Node.js Tools for Visual Studio 1.0  VS 2013, 2013, VS Express 2013  Project Templates  Web Sites, Apps, Worker Roles, VMs/Servers  Typeahead  Dependency Management  Publishing  Using Publishing credentials  Deployment via Git  Remote Debugging  Even on Linux!
  31. 31. Node.js on Azure IaaS/PaaS
  32. 32. Azure Virtual Machines – OS Options Windows Server 2008 and 2012 OpenSUSE and SUSE Enterprise CentOS Ubuntu Oracle Linux
  33. 33. Node at vmdepot.msopentech.com
  34. 34. azure topic verb options Command Line Syntax Overview prompt> account account location account affinity-group vm vm disk vm endpoint vm image service service cert site config download import list show delete start restart shutdown capture create attach detach browse set username password dns-prefix vm-name lb-port target-image-name source-path disk-image-name size-in-gb thumbprint value -v -vv
  35. 35. Automation Support Capabilities • Fully Customize VM with Data Disks and Endpoint Configuration • Automate Virtual Network Settings
  36. 36. Intro to Websocket Deploying Web Sites on Windows
  37. 37. 37 http://www.anglebrackets.org WebSocket  Two-way browser communication  HTTP/1.1 upgrade header for communication  Keeps connections “open” after sending or receiving messages  UTF-8 encoding (no binary)  Just a transport – Challenges:  Server needs to perform a handshake based on the WebSocket protocol, and implement security separately  WebSocket not supported by all browsers/versions
  38. 38. 38 http://www.anglebrackets.org Node.js with Socket.io  Node.js - Scalable, Event-Driven HTTP server  JavaScript and simple API  Socket.io on Node.js  Socket.io adds the WebSocket protocol and server-side security to Node.js  HTML5 browsers can receive WebSocket connections and keep them “open”.
  39. 39. 40 http://www.anglebrackets.org
  40. 40. 41 http://www.anglebrackets.org Conference Scheduler  Attendees can track sessions, vote sessions up and down  Offline Capabilities  IndexedDB  CouchDB VM for Data Storage  Web site hosting the application  Node.js  Grunt
  41. 41. Demo Architecture
  42. 42. 43 http://www.anglebrackets.org Local or Server – CouchDb or PouchDB app.replicate = function(callback, type) { Pouch.replicate(CONF.local.userprefs, CONF.remote.userprefs, function() {callback("User Perferences");}); Pouch.replicate(CONF.remote.sessions, CONF.local.sessions, function() {callback("Session Data");});};
  43. 43. 44 http://www.anglebrackets.org Get Sessions from CouchDB app.loadSessions = function() { $("#loader").modal("show"); $.getScript("sessions.js?" + Math.random()).then(function(data) { $("#loader").modal("hide");_.each(CONF.sessions, function(s) {var models = app.sessionList.where({ name: s.name});if(models.length === 0) {model = new app.Model.Session();} else {model = models[0];} model.set(s);model.server = CONF.local.sessions; model.save();app.sessionList.add(model);}); app.sessionList.fetch();
  44. 44. 46 http://www.anglebrackets.org Handling connections var socket = io.connect(document.location.protocol + '//' + document.location.host + '/'); var connected = false; socket.on('connected', function(data) { connected = true; }); socket.on('message', function(data) { //console.log('Message', data); if (typeof processMessage[data.sender] === 'object') { if (typeof processMessage[data.sender][data.type] === 'function') { processMessage[data.sender][data.type](data);
  45. 45. 47 http://www.anglebrackets.org Notifications Function addAudience(data, isPresenter) { data = data || {}; data.img = data.img || ('/img/avatar' + (1 + parseInt(Math.random() * 10 % 3)) + '.png'); data.data = data.data || {}; $('#audienceList').append($('<img>', { src: data.img, class: (isPresenter ? 'presenter' : ''), title: data.data.name }).data('id', data.id)); notify((data.data.name || 'Someone') + ' joined the meeting'); }
  46. 46. 48 http://www.anglebrackets.org Broadcasting var broadcast = function(sender, type, msg) { socket.emit('message', { sender: sender, type: type, data: msg }); };
  47. 47. 49 http://www.anglebrackets.org Where to learn more Node.js http://nodejs.org Node.js Dev Center http://azure.microsoft.com/en-us/develop/nodejs/ Node Tools for Visual Studio https://nodejstools.codeplex.com/ Code Samples Today: https://github.com/axemclion Tutorial: Building a multi-tier cloud application on Windows Azure using MongoLab, node.js, and Socket.IO http://msopentech.com/blog/2013/09/18/tutorial-building-multi-tier-cloud-application-windows-azure-using- mongolab-node-js-socket-io/ Tutorial – Building a Multi-Tier Windows Azure Web application use Cloudant’s Couchdb-as-a- Service, node.js, CORS, and Grunt http://msopentech.com/blog/2013/12/19/tutorial-building-multi-tier-windows-azure-web-application-use- cloudants-couchdb-service-node-js-cors-grunt-2/ Tutorial: Build and deploy a Node.js web site to Azure http://azure.microsoft.com/en-us/documentation/articles/web-sites-nodejs-develop-deploy-mac/
  48. 48. Q&A

×