Node.JS Paris Meetup - the Tessel microcontroller, Azure and Project Oxford
Node.js on microsoft azure april 2014
-
Upload
brian-benz -
Category
Internet
-
view
110 -
download
1
description
Transcript of Node.js on microsoft azure april 2014
Node.js Development in the
Cloud with Azure
Brian Benz, Sr. Technical Evangelist
Microsoft Open Technologies, Inc.
2 http://www.anglebrackets.org
Agenda
Azure
Node
Node on Azure
Web Sites
IaaS/PaaS
Examples
Q&A
Azure
Flexible
Azure IaaS, PaaS, SaaS
Application Scenarios
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
Intro to Node.js
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 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 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
Setting up Node.js for Azure
12 http://www.anglebrackets.org
Download Node.js nodejs.org
13 http://www.anglebrackets.org
npm installer - www.npmjs.org
14 http://www.anglebrackets.org
Get the SDK - azure.microsoft.com/downloads
15 http://www.anglebrackets.org
Get the CLI - azure.microsoft.com/downloads
16 http://www.anglebrackets.org
Web Platform Installer – CLI and SDK
17 http://www.anglebrackets.org
Install Results
18 http://www.anglebrackets.org
Docs - azure.microsoft.com/documentation/
Node.js on Azure Web Sites
20 http://www.anglebrackets.org
Node.js on Azure Web Sites
Node Options in the Gallery
Local Git Repository
21 http://www.anglebrackets.org
Node.js from the Web Site Gallery
22 http://www.anglebrackets.org
New > Web Site > Quick Create > Name and Click
23 http://www.anglebrackets.org
24 http://www.anglebrackets.org
Node.js from Local Git
25 http://www.anglebrackets.org
Get git - http://git-scm.com/downloads
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 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 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:\home\site\repository'
to: 'D:\home\site\wwwroot'
remote: Deleting file: 'hostingstart.html'
remote: Copying file: 'server.js'
29 http://www.anglebrackets.org
Updating your Repository
git add .
git commit -m “commit message"
git push azure master
<Password>
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!
Node.js on Azure IaaS/PaaS
Azure Virtual Machines – OS Options
Windows Server 2008 and 2012
OpenSUSE and SUSE Enterprise
CentOS
Ubuntu
Oracle Linux
Node at vmdepot.msopentech.com
azure topic verb options
Command Line Syntax Overview
prompt>
accountaccount locationaccount affinity-groupvmvm diskvm endpointvm imageserviceservice certsiteconfig
downloadimportlistshowdeletestartrestartshutdowncapturecreateattachdetachbrowseset
usernamepassworddns-prefixvm-namelb-porttarget-image-namesource-pathdisk-image-namesize-in-gbthumbprintvalue-v-vv
Automation Support
Capabilities
• Fully Customize VM with Data Disks and Endpoint Configuration
• Automate Virtual Network Settings
Intro to WebsocketDeploying Web Sites on Windows
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 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”.
40 http://www.anglebrackets.org
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
Demo Architecture
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");});};
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();
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);
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');
}
48 http://www.anglebrackets.org
Broadcasting
var broadcast = function(sender, type, msg) {
socket.emit('message', {
sender: sender,
type: type,
data: msg
});
};
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 Azurehttp://azure.microsoft.com/en-us/documentation/articles/web-sites-nodejs-develop-deploy-mac/
Q&A