Node.js is one one of the the most popular growing platforms for development. I started a series of posts dedicated to Node.js , starting with two articles about Node.js and Microsoft SQL Server ( you can see part 1 and part 2 ) . This blog discusses how you can use Node.js and Microsoft Azure Table Storage . Open source solutions (OSS), are very suitable for the implementation of platform independent and/or cloud applications. Node.js is widely used in the actual implementation of such cloud applications. I will try demonstrate in several blogs some details how to use Node.js with Microsoft Azure Storage .
What is Azure Storage?
Microsoft Azure storage services allow us to store/retrieve the NON RELATIONAL data to/from Microsoft Cloud environment. (For relational data, SQL Azure services are used).
In Microsoft Azure Storage, the data can be stored in 4 different formats (v.i.z. Blobs, Tables and Queues, File Storage (in preview )). The retrieval/storage of the above data is done in RESTful way.
- Blob storage stores file data. A blob can be any type of text or binary data, such as a document, media file, or application installer.
- Table storage stores structured datasets. Table storage is a NoSQL key-attribute data store, which allows for rapid development and fast access to large quantities of data.
- Queue storage provides reliable messaging for workflow processing and for communication between components of cloud services.
- File storage offers shared storage for legacy applications using the standard SMB 2.1 protocol. Azure virtual machines and cloud services can share file data across application components via mounted shares, and on-premise applications can access file data in a share via the File service REST API.
This article is focused on how to handle Azure Table services with Node.js
The Azure Table storage service stores large amounts of structured data. The service is a NoSQL datastore which accepts authenticated calls from inside and outside the Azure cloud.
The Table service contains the following components:
Table entities represent the units of data stored in a table and are similar to rows in a typical relational database table. Each entity defines a collection of properties. Each property is key/value pair defined by its name, value, and the value’s data type. Entities must define the following three system properties as part of the property collection:
- PartitionKey – The PartitionKey property stores string values that identify the partition that an entity belongs to. This means that entities with the same PartitionKey values belong in the same partition. Partitions, as discussed later, are integral to the scalability of the table.
- RowKey – The RowKey property stores string values that uniquely identify entities within each partition.
- Timestamp – The Timestamp property provides traceability for an entity. A timestamp is a DateTime value that tells you the last time the entity was modified. A timestamp is sometimes referred to as the entity’s version. Modifications to timestamps are ignored because the table service maintains the value for this property during all inserts and update operations.
Consider PartitionKey, RowKey in your design. Think of PartitionKey and RowKey as being a primary index.
Azure Tables use keys that enable efficient querying, and you can employ one—the PartitionKey—for load balancing when the table service decides it’s time to spread your table over multiple servers. A table doesn’t have a specified schema.
Partitions represent a collection of entities with the same PartitionKey values. Partitions are always served from one partition server and each partition server can serve one or more partitions.
Dealing with an Azure Table Storage
- Microsoft Azure SDK for Node.js
It is an official Microsoft Azure SDK for Node.js. This project provides a Node.js package that makes it easy to consume and manage Microsoft Azure Services.
The listed snippets below demonstrate how to manage Azure Table service using Microsoft Azure SDK for Node.js.
This is easy to do since the Azure SDK will look for credentials using environment variables first. The magical environment variable names are
- Create a table service
Set credentials using environment variables
Set credentials explicitly using local variables
- Insert an entity
- Query entities
It is a simplified Azure Table Storage client library for Node.js that supported:
- creating, deleting and listing tables
- creating, updating, querying and deleting entities
- batch operation support
- generating SAS (Shared Access Signature) and using it for authentication
Code samples below show how to use azure-table-node module to work with Azure Table Storage
- Set Azure Storage credentials
- Create an Azure Table
- Display an Azure Table
- List all Azure Tables
- Delete an Azure Table
Developers on the Microsoft Azure Platform should become familiar with how Table Storage works and how it differs from the relational databases they are used to. Knowing how table storage works will help you determine if it is a good fit for your particular requirements.
My original post is published on Infragistics community blog .
You can download source code from Git repository .
If you want more information about how to use Microsoft Azure Storage & Node.js feel free to contact me at firstname.lastname@example.org
You can learn more about Node.js , Microsoft Azure and related events like Azure Bootcamp Bulgaria if you follow us on Twitter @mihailmateev and @Infragistics and stay in touch on Facebook, Google+, LinkedIn and Infragistics Friends User Group !