Getting Started with FogJS

Here's how to quickly get up and running with FogJS

Blob Storage Example

It's easy to get a simple example up and running with FogJS. Here are the steps for interacting with Azure Blob Storage

  1. FogJS (as well as the Azure SDK for Node.js) requires Node and NPM, so make sure that you have each of these installed.
  2. Open a Node.js command prompt and navigate to your app's directory.
  3. Install FogJS with the command "npm install fogjs"
  4. Create a file (I use the name test.js as an example) with code such as the sample that follows and run it with the command "node test.js".
var fog = require("fogjs"); 
var fogBlob = fog.blobStorage;

var containerName = "testcontainer";
var blobName = "testblob";

fogBlob.createBlockBlobFromText({
    "containerName": containerName, 
    "blobName" : blobName, 
    "blobText": "My super awesome text to upload"
}).then(function() {
    return fogBlob.getBlobToText({
        "containerName": containerName, 
        "blobName" : blobName
    });
}).then(function(response) {
    console.log("The blob contains the text: " + response.text);
    return fogBlob.deleteBlob({
        "containerName": containerName, 
        "blobName" : blobName
    });                    
}).then(function(response) {
    console.log("done");
});

Table Storage Example

If you haven't installed FogJS, follow steps 1 through 4 from the Blob Storage example and use the following code to interact with Table Storage.

var fogjs = require("fogjs"); 
var fog = fogjs.tableStorage;

var testTableName = "testTableName";
var rowKey = "myRowKey";
fog.insertEntity({
    "tableName" : testTableName,
    "entity": {
        "PartitionKey" : "testPartition",
        "RowKey" : rowKey,
        "MyCustomField" : "Legends of Awesomeness!"
    }
}).then(function(response){
    console.log(response.entity.RowKey);
    return fog.deleteEntity({
        "tableName" : testTableName, 
        "entityDescriptor": {  
            "PartitionKey" : "testPartition",
            "RowKey" : rowKey,
        }
    });
});

Service Bus Example

If you haven't installed FogJS, follow steps 1 through 4 from the Blob Storage example and use the following code to interact with Table Storage.

var fogjs = require("fogjs"); 
var fog = fogjs.serviceBus;

var queueName = "testQueue";

fog.receiveQueueMessage({"queuePath": queueName})
.then(function(response) {
    console.log(response.receivedMessage.body);
});

fog.sendQueueMessage({ "queuePath" : queueName, "message" : "Test Message"});