node.js on windows azure name title microsoft corporation

35
Node.js on Windows Azure Name Title Microsoft Corporation

Upload: corey-horton

Post on 24-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Node.js on Windows Azure Name Title Microsoft Corporation

Node.js on Windows Azure

NameTitle Microsoft Corporation

Page 2: Node.js on Windows Azure Name Title Microsoft Corporation

Agenda

What is node.js?

When to use node.js?

Node.js on Windows Azure

Page 3: Node.js on Windows Azure Name Title Microsoft Corporation

What is node.js?

JavaScript on the Server!Event driven I/O server-side JavaScriptNot thread based, each connection uses only a small heap allocationEfficient and highly scalable

Page 4: Node.js on Windows Azure Name Title Microsoft Corporation

JavaScript Server

Started 2009 by @ryahOpen Source (MIT license)Sponsored by Second most popular project on GitHub

Node process

V8 runtime

Your app.js

Page 5: Node.js on Windows Azure Name Title Microsoft Corporation

Work queue

Async Model

Single-threaded event loopThread must not stop for anything!

Run DB query

Page 6: Node.js on Windows Azure Name Title Microsoft Corporation

Doing CPU intensive processingVideo transcoding, etc.Though it could proxy to a transcoder

“Forms over data” CRUD appsRails/ASP.NET give you more

Realtime commsSockets, polling, etc.

Custom network servicesMedia servers, proxies, etc.

JSON web servicesThin app layer on top of a datastore

Client-oriented web UIsAnything you’d build with Sinatra

Node is…Excellent for: OK for:

Wrong for:

Page 7: Node.js on Windows Azure Name Title Microsoft Corporation

ProsJavaScriptCommon to almost all developersSame language on server & client

Clean, consistent API

Simple concurrency modelEven low-skilled devs can manage it

Idle connections are nearly freeLong polling? No problem.Very high capacity for concurrent reqs

Very modularPlug in whatever behaviors you need

Not a lot of standard frameworkTesting? Validation? Pick your own approach…

Young & not yet widely deployed

Pretty bare-metalNot aimed at drag-drop devs...!

ConsPros and Cons

Page 8: Node.js on Windows Azure Name Title Microsoft Corporation

Application Frameworks

Connect Standard middleware

Routing + Templates (like Sinatra)

Full-stack MVC (wants to be like Rails)

(fab) Totally bizarre DSL for combining modules

Ni Full-stack MVC (wants to be like Rails)

Inspired by ASP.NET MVC

Page 9: Node.js on Windows Azure Name Title Microsoft Corporation

Node.js on Windows

Native node.exe IISNode – a native IIS 7.x module that allows hosting of node.js applications in IISMost modules supported as isPerformance on par with Linux implementation

Page 10: Node.js on Windows Azure Name Title Microsoft Corporation

IIS NodeProcess managementScalability on multi-core serversAuto-updateAccess to logs over HTTPSide by side with other content typesMinimal changes to node.js application codeIntegrated management experience

Page 11: Node.js on Windows Azure Name Title Microsoft Corporation

IIS Node

<configuration><system.webServer><handlers><add name="iisnode"

path="app.js"verb="*"modules="iisnode" />

</handlers> </system.webServer>

</configuration>

IIS

iisnode (native module)

Page 12: Node.js on Windows Azure Name Title Microsoft Corporation

Node Package ManagerPackage manager for nodeAllows you to easily add modules to your applicationUse through the command line:C:\nodehello> npm install express

Page 13: Node.js on Windows Azure Name Title Microsoft Corporation

NPM – Node Package Manager

coffee-script

express

connect

socket.io

jade

redis

async vows request

> npm install somepackage

Page 14: Node.js on Windows Azure Name Title Microsoft Corporation

Install node.js on WindowsSingle Install: node.js + npmDownload: bit.ly/nodejsdownload

Page 15: Node.js on Windows Azure Name Title Microsoft Corporation

Hello World

Page 16: Node.js on Windows Azure Name Title Microsoft Corporation

Node.js “Hello World”

server.js File:

var http = require('http');

http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'});

res.end('Hello, world! ');}).listen(80);

Page 17: Node.js on Windows Azure Name Title Microsoft Corporation

Run node.js “Hello World”

C:\nodehello> node.exe server.js

Page 18: Node.js on Windows Azure Name Title Microsoft Corporation

Node.js “Hello World”

Page 19: Node.js on Windows Azure Name Title Microsoft Corporation

Node.js + Express

demo

Page 20: Node.js on Windows Azure Name Title Microsoft Corporation

Node.js On Windows Azure

Page 21: Node.js on Windows Azure Name Title Microsoft Corporation

Node.js on Windows Azure

Web RoleUses IISNode

Worker RoleRuns node.exe as role entry point

PowerShell CmdletsWindows Azure SDK for node.js

Page 22: Node.js on Windows Azure Name Title Microsoft Corporation

Visual Studio Not Required

Create, run, and publish all from outside of Visual StudioUse command line and editor

or IDE of your choice

Page 23: Node.js on Windows Azure Name Title Microsoft Corporation

Installation

Single Install using Web Platform InstallerNode.jsIISNodeNPM for WindowsWindows Azure EmulatorsWindows Azure Authoring Components Windows Azure PowerShell for node.js

Page 24: Node.js on Windows Azure Name Title Microsoft Corporation

Node Roles

Node Web Role

IIS

iisnode (native module)

Node Worker RoleRole

Role Entry Point

Page 25: Node.js on Windows Azure Name Title Microsoft Corporation

PowerShell Cmdlets

Create Hosted ServiceLaunch Node application in local emulatorSet configuration settingsDeploy to Windows Azure

Page 26: Node.js on Windows Azure Name Title Microsoft Corporation

Create a Project

Page 27: Node.js on Windows Azure Name Title Microsoft Corporation

Add Web Role

Page 28: Node.js on Windows Azure Name Title Microsoft Corporation

Start Local Emulator

Page 29: Node.js on Windows Azure Name Title Microsoft Corporation

Windows Azure Node SDK

Windows Azure StorageBlobsTablesQueues

> npm install azure

Page 30: Node.js on Windows Azure Name Title Microsoft Corporation

Blob Storage Examples

var azure = require('azure'); var blobClient = azure.createBlobService();

// Create Blob from Text var text = 'the text of my blob'; blobClient.createBlockBlobFromText('mycontainer', 'myblob', text, function (error, blockBlob, response) {

// Blob created });

// Get Blob Text blobClient.getBlobToText('mycontainer', 'myblob', function (error, text, blockBlob, response) {

// Blob text retrieved });

// Delete Blob blobClient.deleteBlob('mycontainer', 'myblob', function (error, isSuccessful, response) {

// Container deleted });

Page 31: Node.js on Windows Azure Name Title Microsoft Corporation

Table Storage Examples

var azure = require('azure'); var tableClient = azure.createTableService();

// Insert Entity var item = new MyEntity(); item.PartitionKey = 'part1'; item.RowKey = uuid(); tableClient.insertEntity('mytable', item, function (error, entity, response) {

// Entity saved });

// Query Entity tableClient.queryEntity('mytable', item.PartitionKey, item.PartitionKey, function (error, successful, response) {

// Do something });

// Delete Entity tableClient.deleteEntity('mytable', item, function (error, entity, response) {

// Entity deleted });

Page 32: Node.js on Windows Azure Name Title Microsoft Corporation

Storage Queue Example

var azure = require('azure');

var queueClient = azure.createQueueService();

// Enqueue a Message

queueClient.createMessage('myqueue', 'my message text',

function (error, queueMessageResult, response) {

// Do something });

// Get Messages

queueClient.getMessages('myqueue',

function (error, queueMessageResults, response) {

// Do Something

});

Page 33: Node.js on Windows Azure Name Title Microsoft Corporation

Task List

demo

Page 34: Node.js on Windows Azure Name Title Microsoft Corporation

Summary

Node.js OverviewIIS NodeNode Modules + NPMNode.js + Windows AzureWindows Azure SDK for node.js

Page 35: Node.js on Windows Azure Name Title Microsoft Corporation

© 2011 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to

be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.