Node-Azure is a Node.js package (available via NPM) which allows native javascript access to the Windows Azure storage API. This is embryonic and incomplete, but proves the concepts and looks like a good basis for further work.
Node-Azure currently supports most of methods on these storage types:
- Blob storage
- Table storage
- Queues
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"
}
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!"
});
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
});
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
});
npm install node-azure
Or alternatively, manually copy the repository into a node_modules/node-azure folder.
By Rob Blackwell, Richard Astbury, Max Spencer http://www.two10degrees.com
Any feedback / patches gratefully received
Depends on xml2js which can be installed via NPM
- Implement the wider APIs
- Make it NPM installable
- Implement a parser for Azure connection strings
- Implement a queue reader that looks like a callback
- Implement other Azure APIs? AppFabric? Service Management?