Setting Up a CDN on Azure and Using it With Both Visual Studio 2013 and a Node.js Server

The first thing you need to do is head about to azures management portal and log in:

Click on the plus sign for create new account at the bottom of the page:

Select Data Services, Storage, Quick Create:

Choose a name for your storage service and select the location closest to you.


Once created select click on the plus sign at the bottom in order to create another account:


Select app services, cdn, quick create, and select the storage account you just created:


Select the cdn and click on enable query strings at the bottom:


Now open up Microsoft visual studio 2013 and open up server explorer:


Right click it select connect to Microsoft Azure Subscription and Log In:


Select Storage, CDN, Blobs:


Right click blobs and select create Blob Container and name it whatever you’d like:


On the window the tab that opens up click on the upload arrow to upload any files you want:

Now that your blob storage has been created and you are now able to populate it with whatever files you wish, let’s take a look at how to access those files from a node server and upload news files.


Let’s start by installing azure-storage: npm install azure-storage. Make sure to add AZURE_STORAGE_ACCOUNT and AZURE_STORAGE_ACCESS_KEY to your environmental variables. You can get the storage access key and the storage account name from the management portal where you created the account.


Go to you storage account, select dashboard and at the bottom you’ll see the options manage access keys
If you click on it the following window will pop up. Copy and paste the account name and access keys into your environmental variables.


Now, on the node application lets add the following code from this Microsoft azure post which allows us to add, download, and delete files from the CDN storage:

var azure = require('azure-storage');
var fs = require('fs');
var blobSvc = azure.createBlobService();
blobSvc.createContainerIfNotExists('test', function(error, result, response){
    // Container exists and allows
    // anonymous read access to blob
    // content and metadata within this container
blobSvc.createBlockBlobFromLocalFile('mycontainer', 'myblob', 'test.txt', function(error, result, response){
    // file uploaded
blobSvc.getBlobToStream('mycontainer', 'myblob', fs.createWriteStream('output.txt'), function(error, result, response){
    // blob retrieved
blobSvc.deleteBlob(containerName, 'myblob', function(error, response){
    // Blob has been deleted

Now your project should be all set up and ready to use a Azure’s CDN storage to host your static files.

Paulo Diniz