node-azure-storage-simple
Simplified interfaces for Azure Storage (Tables, Queues, Blob)
This is an opinionated interface using Promises. You can use the promises interface's .then
and .catch
methods, or you can use ES7-style await
syntax via BabelJS stage 0 support, or something similar. A global Promise
implementation is required, and must be set globally, no searches will be done.
Install
npm install --save azure-storage-simple
Module Interface - Storage
The module exposes a method that will return a Storage interface.
var storage = require('azure-storage-simple')();
var account = process.env.AZURE_STORAGE_ACCOUNT;
var key = process.env.AZURE_STORAGE_ACCESS_KEY;
var cs = process.env.AZURE_STORAGE_CONNECTION_STRING;
var storage = require('azure-storage-simple')(account || cs, key || null);
Underlying services
Because this module exposes only a simplified interface, the azure services interfaces are available.
NOTE: Will use underlying storage
object's authentication credentials, no need to pass them in.
var azure = require('azure-storage-simple/azure-storage');
var tableService = storage.createTableService();
var queueService = storage.createQueueService();
var blobService = storage.createBlobService();
For details on how to use these services see:
Azure Queues
A dramatically simplified interface for using Azure Storage Queues.
var q = service.queue('myQueueName');
await queue.add(value);
var message = await q.one();
var value2 = message.value;
await q.done(message);
Azure Tables
A simplified interface will be used to access table storage. You won't need to wrap your objects, but you will need to specify the partitionKey and rowKey for read and write.
Note: write will do an insertOrMerge, so if you intend to remove field values, set them to null.
var tbl = storage.table('myTableName');
var value = {
'someString': 'value',
'someNumber': 1234,
'someDate': new Date(),
'someObject': {},
'someArray': [],
'falseVal': false,
'trueVal': true
};
await tbl.write('partitionKey','rowKey',value);
var record = await tbl.read('partitionKey','rowKey');
var value2 = result.value;
var records = tbl.query()
.where('PartitionKey eq ?', 'partitionKey')
;
while (records.next) {
records = await records.next();
records
.forEach((record )=>{
});
}
Blob Storage
Allows for simple read-write access to block blobs.
var blob = storage.blob('my-container', {publicAccessLevel : 'blob'});
var result = await blob.write('some/path/file.txt', 'this is a string');
var result = await blob.write('some/path/file.json', {foo:'bar'});
var result = await blob.write('some/path/file.bin', someBuffer);
var result = await blob.write(
'some/path/image.png'
,{
contentType: 'image/png'
}
,imageBuffer
);
var myBuffer = await blob.read('some/path/file.txt');
var myText = myBuffer.toString();
...
var myBuffer = await blob.read('some/path/file.json');
var myObj = JSON.parse(myBuffer.toString());
await blob.delete('some/path/file.ext');