I would like to execute a test.py from my nodeJS back-end, after watching several tutorial i writed this code :
function runTestPy(req, res) {
const spawn = require('child_process').spawn;
const process = spawn('python', ['./test.py']);
process.stdout.on('data', (data) => {
console.log(data.toString());
console.log('out');
});
process.stdout.on('end', () => {
console.log('fin');
});
console.log('merce');
}
module.exports.runTestPy = runTestPy;
runTestPy('', '');
and here my test.py :
print("hello world from python ")
The problem is that the function is working if I launch it independently from the command node test.py, but when I launch it from the project (after a npm run dev) its just do not work, it does not print "hello world from python" and the "out" log.
I think the problem come from
const process = spawn('python', ['./test.py']);
but i just dont know how to install python in nodeJS and how to use it.
'./test.py'.