Let us look at the basic sample, which retrieves the Azure table data into the applications using Node JS.
Introduction
Let us look at a basic sample which retrieves the Azure table data into the applications using Node JS.
Start creating a node application by running npm init. Create the main file (JavaScript file) for writing the core functionality. In my case, index.js will be used.
The dependency files need to be imported. To access the Azure Table Storage data, Azure Storage functions and objects will be used. The npm package called azure-storage package is available for working with Azure Storage. This needs to be imported and installed using npm command.
The following code snippet shows the package.json file created for this project.
From the Azure Table Storage, account name and access keys need to be noted and used in the node application for accessing the Azure Storage data.
Create a port and import necessary packages.
var port = process.env.PORT || 8000; var http = require('http'); var azure = require('azure-storage');
var accountName = "accountname copied from azure portal"; var accessKey = "access key copied from azure portal";
var server = http.createServer(function(request, response) { //response.end("Listening on port %s...", server.address().port); var tableService = azure.createTableService(accountName,accessKey); // explicit var TableQuery = azure.TableQuery; var TableUtilities = azure.TableUtilities; var queryCondition = TableQuery.stringFilter('PartitionKey', TableUtilities.QueryComparisons.EQUAL, "Grade 1"); var query = new azure.TableQuery().where(queryCondition); tableService.queryEntities('azuretesttable', query, null, function(error, result, res) { if (!error) { response.end(JSON.stringify(result)); } else{ console.log(error); } }); });
The following code snippet shows the entire main function logic.
In this article, you have seen the basic example of retrieving the Azure Storage Table data into Node.js application.
Azure Book