0
votes

I am newer to Node/Express and am using this as my backend to integrate with Azure Blob Storage. Specifically, I am able to create an Azure blob container on click client side in Angular by using the following:

Angular Controller (tied to an ng-click event):

  $scope.createContainer = function () {
            // Create Blob Container
            $http.get('/createcontainer').success(function (data) {
                console.log(data);
            });
        };

Node/Express Backend that creates the Blob Container:

app.get('/createcontainer', function (res, req) {

    function generateUnique() {
        function guid() {
            function s4() {
                return Math.floor((1 + Math.random()) * 0x10000)
      .toString(16)
      .substring(1);
            }
            return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
    s4() + '-' + s4() + s4() + s4();
        }

        var containerNamePart1 = guid();
        var now = new Date();
        var containerNamePart2 = dateFormat(now, "yyyymmddhhMMss");

        var containerName = containerNamePart1 + "-" + containerNamePart2;

        blobSvc.createContainerIfNotExists(containerName, function (error, result, response) {
            if (!error) {
                console.log(result);
                if (result === false) {
                    generateUnique();
                }

    // Container exists and allows
    // anonymous read access to blob
    // content and metadata within this container
            }
        });
    }

    generateUnique();
});

What I need to do is pass back the name of the blob container created in my backend (Node/Express) to my Angular front end (controller) so it can be used as a variable for some other operations. How do I pass variables or data from Node/Express backed to the front end for use/consumption?

1

1 Answers

1
votes

I found the issue. In my first line, I had req and res backwards ((res, req) is supposed to be (req, res). With this resolved, I was able to add the following to the success aspect of my blob container creation:

res.send(containerName);

This can be seen right after the console.log where I pass in the containerName.

blobSvc.createContainerIfNotExists(containerName, function (error, result, response) {
            if (!error) {
                console.log(result);
                res.send(containerName);
                if (result === false) {
                    generateUnique();
                }