node.js on windows azure name title microsoft corporation

Post on 24-Dec-2015

217 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Node.js on Windows Azure

NameTitle Microsoft Corporation

Agenda

What is node.js?

When to use node.js?

Node.js on Windows Azure

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

JavaScript Server

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

Node process

V8 runtime

Your app.js

Work queue

Async Model

Single-threaded event loopThread must not stop for anything!

Run DB query

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:

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

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

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

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

IIS Node

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

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

</handlers> </system.webServer>

</configuration>

IIS

iisnode (native module)

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

NPM – Node Package Manager

coffee-script

express

connect

socket.io

jade

redis

async vows request

> npm install somepackage

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

Hello World

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);

Run node.js “Hello World”

C:\nodehello> node.exe server.js

Node.js “Hello World”

Node.js + Express

demo

Node.js On Windows Azure

Node.js on Windows Azure

Web RoleUses IISNode

Worker RoleRuns node.exe as role entry point

PowerShell CmdletsWindows Azure SDK for node.js

Visual Studio Not Required

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

or IDE of your choice

Installation

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

Node Roles

Node Web Role

IIS

iisnode (native module)

Node Worker RoleRole

Role Entry Point

PowerShell Cmdlets

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

Create a Project

Add Web Role

Start Local Emulator

Windows Azure Node SDK

Windows Azure StorageBlobsTablesQueues

> npm install azure

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 });

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 });

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

});

Task List

demo

Summary

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

© 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.

top related