0

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...

  • 2
    Is the `$http` being called in a function that is being called from the view? – charlietfl Oct 31 '17 at 16:55
  • It would be nice to know where is `$http.get` located in your code. – nubinub Oct 31 '17 at 16:59
  • Can it be connected to the CORS ? Please check this, if yes https://stackoverflow.com/questions/42659860/http-get-being-called-twice – Telman Oct 31 '17 at 17:03
  • @charlietfl yes I have a button in my html which is when click calls a function in which $http.get is present – Mohit Khanna Nov 01 '17 at 07:23
  • @nubinub I have updated the question. Please look at it and tell me whats going wrong. – Mohit Khanna Nov 01 '17 at 07:29
  • @TelmanAgababov Thanks for the reply, but I have minimal idea about angular2 and CORS. I am not able to understand from your link, Can you please explain it to me is it related to my ques or not? – Mohit Khanna Nov 01 '17 at 07:33

0 Answers0