39
20.03.2012 Dipl.-Inf. (FH) Johannes Hoppe Getting started with Node.js and MongoDB on MS Azure ®

2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

Embed Size (px)

DESCRIPTION

This talk concentrates on Microsoft's cloud platform, called Azure. Johannes gives an introduction to the new platform and speaks about its possibilities and limitations. By utilizing the Windows Azure SDK for Node.js he is going to demonstrate a simple JavaScript-driven browser game that bases on Node.js and MongoDB.

Citation preview

Page 1: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

20.03.2012 Dipl.-Inf. (FH) Johannes Hoppe

Getting started with Node.js and MongoDB on MS Azure

®

Page 2: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

Hello

01

Page 3: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

Johannes Hoppe IT-Consultant & Web Developer

www.johanneshoppe.de

Page 4: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

JavaScript?

Page 5: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

As a server side

language?

Page 6: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

Executed inside

a database?

Page 7: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

For a hardware-

accelerated

3D game?

Page 8: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

Hosted on

WINDOWS?

Page 9: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

Yes! .of course

Page 10: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

Live Demo solartournament.org

Page 11: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

solartournament.org

Page 12: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

SDK for Node.js

02

Page 13: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

PaaS / IaaS

Visual Studio 2010

Targets .NET, but also and now officially:

Java, PHP, Node.js… MongoDB

platform

Cloud

Page 14: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

Event-driven Asynchronous I/O

JavaScript Google V8 engine

Server-side MIT License

Page 15: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

www.windowsazure.com/en-us/develop/nodejs/

Page 16: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

What you get › node.exe

› iisnode (native IIS module)

› NPM for Windows (package manager)

› […]

Page 17: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

Live Demo / Windows PowerShell

› New-AzureService helloworld

› Add-AzureNodeWebRole

› Start-AzureEmulator -launch

Page 18: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

server.js var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello world!'); }).listen(process.env.PORT);

Page 19: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

Azure SDK for Node.js

Troubleshooter

Page 20: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

Tricky Emulator › Webinstaller: Decide for IIS Express

› Start PowerShell with Admin Rights

Page 21: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

Tricky Emulator › Check the Windows Event log

› Last resort: start node.exe manually

Page 22: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

Deployment / Windows PowerShell

› Get-AzurePublishSettings

› Import-AzurePublishSettings filename.publishSettings

› Publish-AzureService -name UniqueName -location "North

Europe" -launch

Page 23: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

Node.js Web Application Tutorial:

http://www.windowsazure.com/en-

us/develop/nodejs/tutorials/getting-started/

Page 24: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

Roles & Storage

Windows Azure Compute

Web Role Worker Role VM Role

Windows Azure

Storage SQL Azure

Table / Queue / Blob

Page 25: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

Azure Storage Explorer http://azurestorageexplorer.codeplex.com/

Supports blobs, queues and tables

Page 26: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

MongoDB

03

Page 27: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

“Microsoft has been working with 10gen

to provide MongoDB database

integration for Windows Azure,

including deployment packaging,

documentation, and code samples.” MSDN, December 2011: http://msdn.microsoft.com/en-us/library/gg441573.aspx

Page 28: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

http://downloads.mongodb.org/azure/

AzureMongoDeploymentCmdlets.msi

Page 29: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

PowerShell › Only once: Get-AzureMongoDBBinaries

› Add-AzureMongoWorkerRole

› Join-AzureNodeRoleToMongoRole WebRole1

› npm install mongodb

Page 30: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

node-mongodb-native // the normal way

var mongoServer = new MongoServer("localhost", 27017, {});

mongoDb = new MongoDb(MONGO_DATABASE, mongoServer,

{ native_parser: false });

mongoDb.open(function () { });

Page 31: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

On Azure var azureMongoEndpoints = new AzureMongoEndpoint('ReplicaSetRole', 'MongodPort');

azureMongoEndpoints.on('topologyChange', function () {

if (mongoDb != null) {

mongoDb.close();

mongoDb = null;

}

var mongoAzureServer = azureMongoEndpoints.getMongoDBServerConfig();

mongoDb = new MongoDb(MONGO_DATABASE, mongoAzureServer,

{ native_parser: false });

mongoDb.open(function () { });

});

azureMongoEndpoints.on('error', function (error) { throw error; }); }

Page 32: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

Node.js Web Application

with Storage on MongoDB Tutorial:

https://www.windowsazure.com/en-

us/develop/nodejs/tutorials/web-app-with-mongodb/

Page 33: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

Conclusion

04

Page 34: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

Node.js on Azure? › Stable, works like expected

› Often fiddling on the startup scripts

› Installation binaries: slow upload

(a general Azure problem)

› Thumbs up to iisnode

Page 35: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

MongoDB on Azure? › Development version (2.1.1-pre-) of MongoDB

› Not recommended for production.

› No Sharding!

› Works stable for me

Page 36: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

Questions?

Page 37: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

Thank you! blog.johanneshoppe.de

Page 38: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

Next Speaking Engagements › 12.04.2012 – .NET UG Niederrhein: AOP / .NET

› 10.05.2012 – .NET UG Karlsruhe: NoSQL / .NET

› 14.05.2012 – .NET Developer Conference (DDC)

.Nürnberg: NoSQL / .NET (2 talks)

Page 39: 2012-03-20 - Getting started with Node.js and MongoDB on MS Azure

Picture credits

wave © THesIMPLIFY – Fotolia.com

Stressed businessman © Selecstock – Fotolia.com

Ausgewählter Ordner © Spectral-Design – Fotolia.com

Warnhinweis-Schild © Sascha Tiebel – Fotolia.com

Liste abhaken © Dirk Schumann – Fotolia.com