Ask coding questions

← Back to all posts
How do I execute python code in javascript?
ia13ru (43)

The title says it all! So how do I?

Answered by 19ecal (230) [earned 5 cycles]
View Answer
Comments
hotnewtop
19ecal (230)
const { exec } = require("child_process");

exec("python file.py", (error, stdout, stderr) => {
    if (error) {
        console.log(`error: ${error.message}`);
        return;
    }
    if (stderr) {
        console.log(`stderr: ${stderr}`);
        return;
    }
    console.log(`stdout: ${stdout}`);
});

Try that

RYANTADIPARTHI (6008)

not possible in reality.