Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
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.
For documentation on how to host Node.js applications on Windows Azure, please see the Windows Azure Node.js Developer Center.
For documentation on the new cross platform CLI tool for Mac and Linux, please see this reference and this How to Guide
Check out our new IRC channel on freenode, node-azure.
To get the source code of the SDK via git just type:
git clone https://github.com/WindowsAzure/azure-sdk-for-node.git
cd ./azure-sdk-for-node
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 ensure a table exists, call createTableIfNotExists:
var tableService = azure.createTableService();
tableService.createTableIfNotExists('tasktable', function(error){
if(!error){
// Table exists
}
});
A new entity can be added by calling insertEntity:
var tableService = azure.createTableService(),
task1 = {
PartitionKey : 'tasksSeattle',
RowKey: '1',
Description: 'Take out the trash',
DueDate: new Date(2011, 12, 14, 12)
};
tableService.insertEntity('tasktable', task1, function(error){
if(!error){
// Entity inserted
}
});
The method queryEntity can then be used to fetch the entity that was just inserted:
var tableService = azure.createTableService();
tableService.queryEntity('tasktable', 'tasksSeattle', '1', function(error, serverEntity){
if(!error){
// Entity available in serverEntity variable
}
});
The createContainerIfNotExists method can be used to create a container in which to store a blob:
var blobService = azure.createBlobService();
blobService.createContainerIfNotExists('taskcontainer', {publicAccessLevel : 'blob'}, function(error){
if(!error){
// Container exists and is public
}
});
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:
var blobService = azure.createBlobService();
blobService.createBlockBlobFromStream('taskcontainer', 'task1', fs.createReadStream('task1-upload.txt'), 11, function(error){
if(!error){
// Blob uploaded
}
});
To download the blob and write it to the file system, the getBlobToStream method can be used:
var blobService = azure.createBlobService();
blobService.getBlobToStream('taskcontainer', 'task1', fs.createWriteStream('task1-download.txt'), function(error, serverBlob){
if(!error){
// Blob available in serverBlob.blob variable
}
});
The createQueueIfNotExists method can be used to ensure a queue exists:
var queueService = azure.createQueueService();
queueService.createQueueIfNotExists('taskqueue', function(error){
if(!error){
// Queue exists
}
});
The createMessage method can then be called to insert the message into the queue:
var queueService = azure.createQueueService();
queueService.createMessage('taskqueue', "Hello world!", function(error){
if(!error){
// Message inserted
}
});
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.
var queueService = azure.createQueueService(),
queueName = 'taskqueue';
queueService.getMessages(queueName, function(error, serverMessages){
if(!error){
// Process the message in less than 30 seconds, the message
// text is available in serverMessages[0].messagetext
queueService.deleteMessage(queueName, serverMessages[0].messageid, serverMessages[0].popreceipt, function(error){
if(!error){
// Message deleted
}
});
}
});
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:
var serviceBusService = azure.createServiceBusService();
serviceBusService.createQueueIfNotExists('taskqueue', function(error){
if(!error){
// Queue exists
}
});
The sendQueueMessage method can then be called to insert the message into the queue:
var serviceBusService = azure.createServiceBusService();
serviceBusService.sendQueueMessage('taskqueue', 'Hello world!', function(
if(!error){
// Message sent
}
});
It is then possible to call the receiveQueueMessage method to dequeue the message.
var serviceBusService = azure.createServiceBusService();
serviceBusService.receiveQueueMessage('taskqueue', function(error, serverMessage){
if(!error){
// Process the message
}
});
Service Bus topics are an abstraction on top of Service Bus Queues that make pub/sub scenarios easy to implement.
The createTopicIfNotExists method can be used to create a server-side topic:
var serviceBusService = azure.createServiceBusService();
serviceBusService.createTopicIfNotExists('taskdiscussion', function(error){
if(!error){
// Topic exists
}
});
The sendTopicMessage method can be used to send a message to a topic:
var serviceBusService = azure.createServiceBusService();
serviceBusService.sendTopicMessage('taskdiscussion', 'Hello world!', function(error){
if(!error){
// Message sent
}
});
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.
var serviceBusService = azure.createServiceBusService(),
topic = 'taskdiscussion',
subscription = 'client1';
serviceBusService.createSubscription(topic, subscription, function(error1){
if(!error1){
// Subscription created
serviceBusService.receiveSubscriptionMessage(topic, subscription, function(error2, serverMessage){
if(!error2){
// Process message
}
});
}
});
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.
azure.RoleEnvironment.isAvailable(function(error, available) {
if (available) {
// Place your calls to service runtime here
}
});
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:
azure.RoleEnvironment.getRoles(function(error, roles) {
if(!error){
// You can get information about "instance1" of "role1" via roles['role1']['instance1']
}
});
For more examples please see the Windows Azure Node.js Developer Center
Be sure to check out the Windows Azure Developer Forums on Stack Overflow if you have trouble with the provided code.
If you would like to become an active contributor to this project please follow the instructions provided in Windows Azure Projects Contribution Guidelines.
If you encounter any bugs with the library please file an issue in the Issues section of the project.
2012.08.15 Version 0.6.2
FAQs
Microsoft Azure Client Library for node
The npm package azure receives a total of 8,341 weekly downloads. As such, azure popularity was classified as popular.
We found that azure demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.