Let me prefix this with that I am newer to Node/Express.
I have an AngularJS App that is leveraging Node.JS for managing Azure Blob requirements such as creating Blob containers as follows:
function test(containerName) {
blobSvc.createContainerIfNotExists(containerName, function (error, result, response) {
if (!error) {
// Container exists and allows
// anonymous read access to blob
// content and metadata within this container
}
});
};
test('blob4');
The function for creating a container when executed from server.js in Node works as expected and creates a blob container. However, I need to create a blob container on click in my AngularJS app. I envisioned using exports to access and execute functions created in Server.js but have seen some mixed information, especially when Express.js is in the picture, for calling a Node.js function via AngularJS client side since it appears that in an Angular App an http call would have to be made (please see the last answer in this post: Call function in nodejs from angular application).
My questions are as follows:
1) Since my app currently uses Node, Express, and Angular, would I need to use the http in my Angular controller to run Node functions/do all functions written in Node/Server.js require $http to execute if called via AngularJS client side even if they don't call a service but might be a function performing something such as math? Example of an Express based call:
function MyCtrl($scope, $http) {
// $http is injected by angular's IOC implementation
// other functions and controller stuff is here...
// this is called when button is clicked
$scope.batchfile = function() {
$http.get('/performbatch').success(function() {
// url was called successfully, do something
// maybe indicate in the UI that the batch file is
// executed...
});
}
}
2) Or is using exports, such as listed in this post more common practice, where the function is defined as an export and then imported via a requires: What is the purpose of Node.js module.exports and how do you use it?. If so, would I do something like the following?:
Node Server.JS File:
var myFunc1 = function() { ... };
exports.myFunc1 = myFunc1;
Within an AngularJS Controller (not including as a dependency):
var m = require('pathto/server.js');
m.myFunc1();
3) Lastly, am I completely off base and there is a common practice for calling node.js functions from an Angular Controller that I am missing?