Shaun Xu

The Sheep-Pen of the Shaun



Shaun, the author of this blog is a semi-geek, clumsy developer, passionate speaker and incapable architect with about 10 years’ experience in .NET and JavaScript. He hopes to prove that software development is art rather than manufacturing. He's into cloud computing platform and technologies (Windows Azure, Amazon and Aliyun) and right now, Shaun is being attracted by JavaScript (Angular.js and Node.js) and he likes it.

Shaun is working at Worktile Inc. as the chief architect for overall design and develop worktile, a web-based collaboration and task management tool, and lesschat, a real-time communication aggregation tool.


My Stats

  • Posts - 122
  • Comments - 622
  • Trackbacks - 0

Tag Cloud

Recent Comments

Recent Posts

Article Categories


Post Categories



It has been long time didn’t blog anything since last November. There are many exciting things happened during this period. I attend Microsoft TechED 2012 China and provided a session about Node.js and Windows Azure. I also provided a small but funny session at the Microsoft China Community New Year Party on this January. Then I enjoyed Chinese New Year at Lvshun, a quiet and beautiful city aside Bohai Bay with my wife, where her hometown is.

But I decided to write something when I read this. On February, Microsoft announced that the Windows Azure Store had just expanded availability to new 25 markets, includes Hong Kong SAR, which is the country/region for my Windows Azure account. This means I can try this fantastic feature with my subscription.


Windows Azure Store

Windows Azure Store is a brand new service provided by Windows Azure platform. It likes a service market, where you can buy services provided by many third-party publishers. With Windows Azure Store, as a developer we can:

1. Choose from popular app services including: AppDynamics (monitoring and scaling as a service), New Relic (performance management and monitoring), SendGrid (email delivery as a service) and more.

2. Find the data your app needs from data providers like: Dun & Bradstreet (business insights), Loqate (Worldwide address verification and cleansing service), StrikeIron (Phone number verification service; Sales and use tax rates lookup service), and more.

3. Connect and manage it all from the developer portal: The integrated store UI makes it easy to find, buy, manage the services and data you need directly from the portal.  Integrated billing means you store purposes are added directly to your Windows Azure account.  We also provide connection strings and sample code and help get you started fast, as well as usage data from directly within the Windows Azure management portal.

Furthermore, there are other benefit of using Windows Azure Store.

1. It utilizes similar UI as Windows Azure portal, which means it’s very easy to select, view and purchase.

2. All services are located in Windows Azure data centers. This means we can choose the best region to minimize our cost.

3. We can view the billing report in our Windows Azure subscription management page.

4. Almost all services in Windows Azure Store provides multiple subscription plan and most of them have free subscription.


Windows Azure Store and Windows Azure Marketplace

If you had playing with Windows Azure a while, you might heard that there’s another feature in Windows Azure called Windows Azure Marketplace, where you can buy data and applications published from other venders. It sounds very similar as Windows Azure Store. So what’s different between them? Will Windows Azure Marketplace be replaced by Windows Azure Store.

Here I would like to quote some clarification from Ryan McGee at Microsoft.

The Windows Azure Store and Windows Azure Marketplace will continue to co-exist; there is not a plan to converge them. The reason is, they serve different audiences and they contain different kinds of products.

The Windows Azure Store makes it easy to find and purchase add-ons, and use them to create your applications. While the Windows Azure Marketplace is an online market where ISVs and data publishers can publish and sell finished applications and premium datasets to business customers.

So my understanding is, if you are going to build your application on Windows Azure and want to leverage some services Windows Azure doesn’t provide, you’d better look for the Windows Azure Store. But if you are going to use some data, or you want to find some applications, you can seek in Windows Azure Marketplace.


Node.js + MongoDB by Using Windows Azure Store

Now let’s take a look on how to use Windows Azure Store. In this post I would like to demonstrate how to build a simple website by using Node.js and MongoDB.


As you know, Windows Azure doesn’t offer MongoDB. Before Windows Azure Store was announced, we have to run our own MongoDB service in a work role or in a virtual machine. This is OK but we have to take care for installation, configuration, scaling, etc.. Now we have Windows Azure Store so let’s check if there’s some MongoDB related services. Open the Windows Azure portal, from the navigate click ADD-ONS, and then click the PURCHASE ADD-ONS.


Now we can see the services in the Windows Azure Store. Scroll down the list and we will find a service named MongoLab, which is MongoDB-as-a-Service. Click next icon at the bottom right of the dialog.


Then we can choose the purchase plan. Currently there’s only one free plan for MongoLab which includes one 0.5G MongoDB. Select the valid Windows Azure subscription, specify our MongoDB name and choose the region. This is where our MongoDB will be provisioned.


Then in the last step, review our selection and clicked the PURCHASE icon.

If you found in the last step it said “We’re sorry, we cannot estimate the bill at this time.” this because you had registered Windows Azure Marketplace with different country/region. To solve this issue, you can log in the Windows Azure Marketplace and change the country/region to the one your Windows Azure subscription is.

After several seconds our MongoDB will be established in that region.


The connection information can be retrieved by clicking the CONNECTION INFO button at the bottom. We will use this information in our Node.js application later.



Next, we will create a new Windows Azure Website and write our Node.js code. Ref how to use Windows Azure Website and publish through local GIT, please refer my previous post. Just ensure that we specify the same region when creating website so that the network traffic will not be billed.


After cloned it to local disk we will add the .gitignore and package.json files. The content would be like this.

   1: node_modules
   1: {
   2:   "name": "nodemongotest",
   3:   "version": "1.0.0",
   4:   "dependencies": {
   5:     "mongoose": "~3.5.7",
   6:     "express": "~3.1.0"
   7:   }
   8: }

And then install “express” and “mongoose” modules through NPM command. “mongoose” is the module we are going to use to connect our MongoDB.

For more information about the “mongoose” module please refer its website.

Then, create our Node.js source code file named “server.js” and paste the code from below. Make sure to replace the MongoDB connection string by your MongoDB connection information in line 16.

   1: (function () {
   2:     "use strict";
   4:     var app = require("express")();
   5:     var server = require("http").createServer(app);
   7:     var mongoose = require("mongoose");
   8:     var Schema = mongoose.Schema;
   9:     var ObjectId = Schema.ObjectId;
  11:     var guestSchema = new Schema({
  12:         client_ip: String,
  13:         request_date: String
  14:     });
  16:     var conn = mongoose.createConnection("mongodb://");
  17:     // var conn = mongoose.createConnection("mongodb://");
  18:     var GuestItem = conn.model("GuestItem", guestSchema);
  20:     var guestCount = function (req, callback) {
  21:         // retrieve the client request ip and date
  22:         var request_date = (new Date()).toString();
  23:         var request_ip = req.header('x-forwarded-for') || req.connection.remoteAddress;;
  24:         // try to insert into mongo
  25:         var guest = new GuestItem;
  26:         guest.client_ip = request_ip;
  27:         guest.request_date = request_date;
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
  •   Short Url: