I have a child process (.exe file) written in c++ which the child process of my node API, which is in turn being called by angular get API. Now the problem is this angular API calls the node API twice without getting a response from the first call on its own and initiates the child process(the .exe file) twice in the background. I have implemented angular promise to overcome browser timeouts, still it calls node api twice. Any sort of help is welcomed.
This is the anularjs get request with promise.
angular.module('fileUpload', ['ngFileUpload'])
.controller('imgController',function(Upload,$window,$scope,$http){
$scope.btnDisabled = false;
$scope.analyse = "Analyse";
$scope.analyseFunc = function(){
$scope.btnDisabled = true;
$scope.analyse = "Analysing...";
$http.get('/api/callingExe').then(function(res){
console.log(res);
if(res.data == "ok"){
$scope.btnDisabled = false;
$scope.analyse = "Analyse";
$scope.msg = "COMPLETED!!";
} else{
$scope.btnDisabled = false;
$scope.analyse = "Analyse";
$scope.msg = "Internal Server Error : " + res.status + "Please Try again later !";
}
}).catch(function(error){
console.log("StatusCode: 503, Data: " + error);
})
};// analyseFunc
});//controller
This is the node api which is being called by angularjs and further initiates the child process.
app.get('/api/callingExe', function(req,res,next){
console.log("processing...");
exec(file, [args],function(err, data) {
console.log('err ' + err)
console.log('data ' + data.toString());
}).on('exit', (code) => {
console.log(`child process exited with code ${code}`);
//something
res.end("ok");
});//exe on exit
});//api callingExe
UPDATE I am disabling the button after 1 click. Also funny thing is once the api is being called, then the duplicate one fires after sometime (2 mins approx).
This is what i get on my terminal and exe file gets executed twice. If anyone has any idea please guide me on this.
processing...
GET /api/callingExe - - ms - -
processing...