Introducing Node-Azure

Node-Azure is a Node.js package (available via NPM) which allows native javascript access to the Windows Azure storage API.

Node-Azure currently supports most of methods on these storage types:

  • Blob storage
  • Table storage
  • Queues

Getting Started

To include the node-azure dependency, and set up the details of your account, include these lines of code:

// include the node-azure dependency
var azure = require('azure');
	
// every request has an account parameter, which is an object like this:
var account = {
  name : "YOURACCOUNTNAME",
  key : "YOURACCOUNTKEY",
  blob_storage_url : "https://YOURACCOUNTNAME.blob.core.windows.net",
  table_storage_url : "https://YOURACCOUNTNAME.table.core.windows.net",
  queue_storage_url : "https://YOURACCOUNTNAME.queue.core.windows.net"
}

Blob Examples

Upload text as a blob:

azure.blob.put_blob(account, "container", azure.blob.BlockBlob, "blobname",
  "Hello world!", {'Content-Type': "text/plain"}, callback);

Download a blob:

azure.blob.get_blob(account, "container", "blobname", function(x) {
  // x == "Hello world!"
});

Table Examples

Insert an entity:

azure.tables.insert_entity(account, 'tablename',
  { RowKey:'123', PartitionKey: 'xyz', Value: 'foo' }, callback);

Get an entity:

azure.tables.get_entity(account, 'tablename', 'xyz', '123', function(entity){
  // x == { RowKey:'123', PartitionKey: 'xyz', Value: 'foo' }
});

Query a table:

azure.tables.query_entities(account, 'tablename', "Value+eq+'foo'", function(entities){
  // entities is an array of matching items
});

Queue Examples

Put a message on a queue:

azure.queues.put_message(account, q, {Test:"Message"}, callback);

Pop the message off the queue:

azure.queues.get_message(account, q, function(message){
  // our javascript object is returned: message.Data
});

To install

run:

npm install node-azure

Or alternatively, manually copy the repository into a node_modules/node-azure folder.

Advertisements