Azure SDK for JavaScript

Storage

Connect to Azure Storage

Easily manage blobs, queues, tables, and file shares with the powerful and flexible Azure SDK for JavaScript.

Overview

Azure Blob Storage is a cloud object storage solution that stores unstructured data such as text or binary data. It can be accessed from anywhere in the world via HTTP or HTTPS. You can use Blob Storage to serve images or documents directly to a browser, upload files for backup or sharing, stream video and audio, write to log files, store data for backup and restore, disaster recovery, and data archiving.

Getting Started

First, install the necessary package:

npm install @azure/storage-blob

Then, you can start interacting with Blob Storage:


async function uploadFile(blobServiceClient, containerName, blobName, filePath) {
    const containerClient = blobServiceClient.getContainerClient(containerName);
    const blockBlobClient = containerClient.getBlockBlobClient(blobName);
    await blockBlobClient.uploadFile(filePath, {
        blockSizeMax: 4 * 1024 * 1024, // 4MB
        });
    console.log(`File "${filePath}" uploaded to "${blobName}" in container "${containerName}"`);
}
                

Key Concepts

  • Storage Account: A unique namespace in Azure for your data.
  • Container: A logical grouping of blobs.
  • Blob: A file stored in Azure Storage.
  • Block Blob: Optimized for storing large amounts of unstructured data (e.g., images, videos, documents).
  • Append Blob: Optimized for append operations, like logging.
  • Page Blob: Optimized for random read/write operations.

API Reference

  • BlobServiceClient: The primary client for interacting with Blob Storage.
  • ContainerClient: Client for managing containers.
  • BlockBlobClient: Client for managing block blobs.
  • UploadOptions: Options for upload operations.
  • Full Blob API Documentation

Overview

Azure Queue Storage is a service that stores large numbers of messages that can be accessed from anywhere in the world via authenticated HTTP or HTTPS calls. A single queue message can be up to 64 KB in size, and a storage account can contain an unlimited number of queues, up to the limit of the storage account's total capacity.

Getting Started

Install the package:

npm install @azure/storage-queue

Example of adding a message:


async function addMessage(queueServiceClient, queueName, messageText) {
    const queueClient = queueServiceClient.getQueueClient(queueName);
    await queueClient.sendMessage(messageText);
    console.log(`Message "${messageText}" added to queue "${queueName}"`);
}
                

Key Concepts

  • Queue: A collection of messages.
  • Message: A unit of data stored in a queue.
  • Dequeue: Retrieving a message from the queue.
  • Peek: Viewing a message without removing it.

API Reference

Overview

Azure Table Storage is a NoSQL key-value store that allows you to store large amounts of structured, non-relational data. It's a cost-effective and scalable solution for many types of applications.

Getting Started

Install the package:

npm install @azure/data-tables

Example of inserting an entity:


async function insertEntity(tableClient, entity) {
    await tableClient.createEntity(entity);
    console.log("Entity inserted successfully.");
}
                

Key Concepts

  • Storage Account: The top-level resource.
  • Table: A collection of entities.
  • Entity: A record in a table, similar to a row in a database.
  • PartitionKey: Groups entities together.
  • RowKey: Uniquely identifies an entity within a partition.

API Reference

  • TableServiceClient: The client for Table Storage.
  • TableClient: Client for managing tables and entities.
  • TableEntity: Represents a record in a table.
  • Full Table API Documentation

Overview

Azure Files offers fully managed cloud file shares that are accessible via the industry-standard Server Message Block (SMB) protocol. You can mount one or more file shares in the cloud or on-premises, allowing you to lift and shift legacy applications that rely on file shares to Azure.

Getting Started

Install the package:

npm install @azure/storage-file-share

Example of creating a share:


async function createShare(shareServiceClient, shareName) {
    await shareServiceClient.createShare(shareName);
    console.log(`Share "${shareName}" created.`);
}
                

Key Concepts

  • Storage Account: The primary resource.
  • File Share: A cloud-based file share.
  • Directory: A folder within a file share.
  • File: A document stored in a directory.
  • SMB Protocol: Used for accessing file shares.

API Reference

  • ShareServiceClient: Client for managing file shares.
  • ShareClient: Client for interacting with a specific share.
  • ShareDirectoryClient: Client for managing directories.
  • ShareFileClient: Client for managing files.
  • Full File API Documentation