適用於 Node.js 的 Azure 儲存體模組Azure Storage modules for Node.js

使用 Azure 儲存體用戶端模組:Use the Azure Storage client module to:

使用管理模組來建立、更新和管理 Azure 儲存體帳戶,並從 Node.js 應用程式查詢及重新產生存取金鑰。Create, update, and manage Azure Storage accounts and query and regenerate access keys from your Node.js apps with the management modules.

用戶端套件Client Package

安裝 npm 模組Install the npm module

安裝 Azure 儲存體用戶端 npm 模組Install the Azure storage client npm module

npm install azure-storage

範例Example

此範例會建立儲存體容器,並將本機檔案 data.txt 上傳至該容器。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

安裝 npm 模組Install the npm module

安裝 Azure 儲存體管理 npm 模組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

深入探索可在應用程式中使用的 Node.js 程式碼範例Explore more sample Node.js code you can use in your apps.