README.md

Windows Azure SDK for Node.js

This project provides a Node.js package that makes it easy to access Windows Azure Services like Table Storage and Service Bus. It also includes a cross platform command line tool for managing Windows Azure Websites and Virtual Machines.

With Windows Azure Websites you can deploy node.js applications to the cloud in just seconds using git.

Getting Started

Download Source Code

Download Package

Alternatively, to get the source code via the Node Package Manager (npm), type

npm install azure

You can use these packages against the cloud Windows Azure Services, or against
the local Storage Emulator (with the exception of Service Bus features).

To use the cloud services, you need to first create an account with Windows Azure. To use the storage services, you need to set the AZURE_STORAGE_ACCOUNT and the AZURE_STORAGE_ACCESS_KEY environment variables to the storage account name and primary access key you obtain from the Azure Portal. To use Service Bus, you need to set the AZURE_SERVICEBUS_NAMESPACE and the AZURE_SERVICEBUS_ACCESS_KEY environment variables to the service bus namespace and the default key you obtain from the Azure Portal.

To use the Storage Emulator, make sure the latest version of the Windows Azure SDK is installed on the machine, and set the EMULATED environment variable to any value ("true", "1", etc.)

To upload a file (assuming it is called task1-upload.txt, it contains the exact text "hello world" (no quotation marks), and it is placed in the same folder as the script below), the method createBlockBlobFromStream can be used:

It is then possible to call the getMessage method, process the message and then call deleteMessage inside the callback. This two-step process ensures messages don't get lost when they are removed from the queue.

Service Bus Queues

Service Bus Queues are an alternative to Storage Queues that might be useful in scenarios where more advanced messaging features are needed (larger message sizes, message ordering, single-operaiton destructive reads, scheduled delivery) using push-style delivery (using long polling).

The createQueueIfNotExists method can be used to ensure a queue exists:

A client can then create a subscription and start consuming messages by calling the createSubscription method followed by the receiveSubscriptionMessage method. Please note that any messages sent before the subscription is created will not be received.

Service Runtime

The Service Runtime allows you to interact with the machine environment where the current role is running. Please note that these commands will only work if your code is running in a worker role inside the Azure emulator or in the cloud.

The isAvailable method lets you determine whether the service runtime endpoint is running on the local machine. It is good practice to enclose any code that
uses service runtime in the isAvailable callback.

The getConfigurationSettings method lets you obtain values from the role's .cscfg file.

azure.RoleEnvironment.getConfigurationSettings(function(error, settings) {
if (!error) {
// You can get the value of setting "setting1" via settings['setting1']
}
});

The getLocalResources method lets you find the path to defined local storage resources for the current role. For example, the DiagnosticStore
resource which is defined for every role provides a location for runtime diagnostics and logs.

azure.RoleEnvironment.getLocalResources(function(error, resources) {
if(!error){
// You can get the path to the role's diagnostics store via // resources['DiagnosticStore']['path']
}
});

The getCurrentRoleInstance method lets you obtain information about endpoints defined for the current role instance:

azure.RoleEnvironment.getCurrentRoleInstance(function(error, instance) {
if (!error && instance['endpoints']) {
// You can get information about "endpoint1" such as its address and port via// instance['endpoints']['endpoint1']['address'] and instance['endpoints']['endpoint1']['port']
}
});

The getRoles method lets you obtain information about endpoints in role instances running on other machines: