Azure Storage modules for Node.js

Use the Azure Storage client module to:

Create, update, and manage Azure Storage accounts and query and regenerate access keys from your Node.js apps with the management modules.

Client Package

Install the npm module

Install the Azure storage client npm module

npm install azure-storage

Example

This example create a storage container and uploads a local file data.txt to it.

const azure = require('azure-storage');
const blobService = azure.createBlobService(storageConnectionString);

const container = 'taskcontainer';
const task = 'taskblob';
const filename = 'data.txt';

blobService.createContainerIfNotExists(container, error => {
  if (error) return console.log(error);
  blobService.createBlockBlobFromLocalFile(
    container,
    task,
    filename,
    (error, result) => {
      if (error) return console.log(error);
      console.dir(result, { depth: null, colors: true });
    }
  );
});

Management Package

Install the npm module

Install the Azure storage management npm module

npm install azure-arm-storage

Example

This example list the storage accounts.

const msRestAzure = require('ms-rest-azure');
const storageManagementClient = require('azure-arm-storage');

const subscriptionId = 'your-subscription-id';

msRestAzure
  .interactiveLogin()
  .then(credentials => {
    const client = new storageManagementClient(
      credentials,
      subscriptionId
    );
    return client.storageAccounts.list();
  })
  .then(accounts => console.dir(accounts, { depth: null, colors: true }))
  .catch(err => console.log(err));

Samples

Explore more sample Node.js code you can use in your apps.