Windows Azure Storage for Node.js

I got really exited after watching the Introduction to Node.js video performed by Ryan Dahl the creator of Node.js, just after that I installed node in my computer and started playing a little bit with Javascript which is one of the languages that I love.

A few days ago I announced the release of the first version (0.0.1) of the waz-storage-js library I wrote in Node.js. The code is based on the waz-storage ruby library written by friend and colleague Johnny Halife who let me contribute with the Tables service and the dm-waztables-adapter for datamapper.

This version allows you to deal only with Blobs but my plan is to include also Tables and Queues in the near future.

Remember that you can always fork the code hosted on Github and contribute to speed up the thing!

Let's play with it and install the package

The library is available as an npm package. To install, run the following command:

npm install waz-storage-js

Configure your account information

var waz = waz.establishConnection({
        accountName: 'your_account_name'
        , accountKey: 'your_key',
        , useSsl: false
      });

And finally read and write data from you Blobs

// Creating a new container
waz.blobs.container.create('myContainer', function(err, result){
});

// Listing existing containers
waz.blobs.container.list(function(err, result){
});

// Finding a container
waz.blobs.container.find('myContainer', function(err, container){

        // Getting container's metadata
        container.metadata(function(err, metadata){
        });

        // Adding properties to a container
        container.putProperties({'x-ms-custom' : 'MyValue'}, function(err, result){
        });

        // Getting container's ACL
        container.getAcl(function(err, result){
        });

        // Setting container's ACL (null, 'blob', 'container')
        container.setAcl('container', function(err, result){
        });

        // Listing blobs in a container
        container.blobs(function(err, result){
        });

        // Getting blob's information
        result.getBlob('myfolder/my file.txt', function(err, blob){

            // Getting blob's contents
            blob.getContents(function(err,data){
                console.log(data);
            });
        });

        // Uploading a new Blob
        result.store('folder/my file.xml', 'content', 'text/xml', {'x-ms-MyProperty': 'value'}, function(err, result){
        });
    }
});

// Deleting containers
waz.blobs.container.delete('myContainer', function(err){
});

Microsoft is working to bring Node.js to both Windows and Azure and I hope my contribution (and why not yours) helps developers in future projects.

Stay tuned! I wil keep you posted.

Published: August 06 2011

  • category:
blog comments powered by Disqus