Getting started
                                 with Node.js and MongoDB on MS Azure



                                                                   ®




20.03.2012
Dipl.-Inf. (FH) Johannes Hoppe
01
Hello
Johannes Hoppe
IT-Consultant & Web Developer
    www.johanneshoppe.de
JavaScript?
As a server side
language?
Executed inside
a database?
For a hardware-
accelerated
3D game?
Hosted on
WINDOWS?
Yes!
.of course
Live Demo
solartournament.org
solartournament.org
02
SDK for Node.js
platform




     Cloud
                         PaaS / IaaS
                         Visual Studio 2010
Targets .NET, but also   and now officially:
Java, PHP, Node.js…      MongoDB
Event-driven   Asynchronous I/O
JavaScript     Google V8 engine
Server-side    MIT License
www.windowsazure.com/en-us/develop/nodejs/
What you get
›   node.exe
›   iisnode (native IIS module)
›   NPM for Windows (package manager)
›   […]
Live Demo / Windows PowerShell
›   New-AzureService helloworld
›   Add-AzureNodeWebRole
›   Start-AzureEmulator -launch
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);
Azure SDK for Node.js
Troubleshooter
Tricky Emulator
›   Webinstaller: Decide for IIS Express
›   Start PowerShell with Admin Rights
Tricky Emulator
›   Check the Windows Event log
›   Last resort: start node.exe manually
Deployment / Windows PowerShell
›   Get-AzurePublishSettings
›   Import-AzurePublishSettings filename.publishSettings
›   Publish-AzureService -name UniqueName -location "North
    Europe" -launch
Node.js Web Application
Tutorial:
http://www.windowsazure.com/en-
us/develop/nodejs/tutorials/getting-started/
Roles & Storage

             Windows Azure Compute


      Web Role          Worker Role       VM Role




        Windows Azure
                                      SQL Azure
           Storage

     Table / Queue / Blob
Azure Storage Explorer
http://azurestorageexplorer.codeplex.com/
Supports blobs, queues and tables
03
MongoDB
“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
http://downloads.mongodb.org/azure/
AzureMongoDeploymentCmdlets.msi
PowerShell
›   Only once: Get-AzureMongoDBBinaries
›   Add-AzureMongoWorkerRole
›   Join-AzureNodeRoleToMongoRole WebRole1
›   npm install mongodb
node-mongodb-native
// the normal way
var mongoServer = new MongoServer("localhost", 27017, {});
mongoDb = new MongoDb(MONGO_DATABASE, mongoServer,
                      { native_parser: false });
mongoDb.open(function () { });
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; }); }
Node.js Web Application
with Storage on MongoDB
Tutorial:
https://www.windowsazure.com/en-
us/develop/nodejs/tutorials/web-app-with-mongodb/
04
Conclusion
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
MongoDB on Azure?
›   Development version (2.1.1-pre-) of MongoDB
›   Not recommended for production.
›   No Sharding!

›   Works stable for me
Questions?
Thank you!
   blog.johanneshoppe.de
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)
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

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