I want to use python scripts with my Node.JS server, but whenever I run the node server, the python script doesn't run. It starts the server but no python runs. I think it's in this part of the code but I'm not exactly sure.
My index.js:
app.post("/readPython", (request, response) => {
var dataToSend;
const python = spawn('python', ['python/cookie.py'], "Kevin");
python.stdout.on('data', function (data) {
dataToSend = data.toString();
});
python.stderr.on('data', data => {
console.error(`stderr: ${data}`);
});
python.on('exit', (code) => {
console.log(`child process exited with code ${code}, ${dataToSend}`);
response.sendFile(`${__dirname}/html/result.html`);
});
});
My python script:
import sys
print("Hello World!")
sys.stdout.flush()
I don't know exactly what I should expect but whatever it is, the script isn't running. Any help?