Thursday, 8 June 2017

response method is getting executed forever in node express js

I'm using below code to execute python script from express js. It's executing properly. But what I see is, the response method is getting executed several times i.e the hello in the below code is getting printed many times in console.Even "console.log(req.params);" is getting executed 2-3 times. I want to understand why this is happening and how can I stop this? I'm new to node express.js.It should stop after receiving response and print the entire data only when response is received fully.Please explain.

 var spawn = require('child_process').spawn, py = spawn('python',['test.py', arg1, arg2]);
 console.log(req.params);
        py.stdout.on('data', (data) => {
          console.log("Hello");
        });



via Nikita Gupta

No comments:

Post a Comment