I'm using Electron.js to build a browser application that hooks up to a flask back-end located in a separate folder in the directory. As of now, I'm using a hacky work-around to exec the back-end:
const bat = cp.exec("cd api && python app.py");
however I would ideally like to spawn a back-end child process in the API folder. How can I do that?
Thanks
The child_process.exec() function has a specific option for the current working directory for the child process.
You can see it in the doc.
child_process.exec(command[, options][, callback])
command <string> The command to run, with space-separated arguments.
options <Object>
cwd <string> | <URL> Current working directory of the child process. Default: process.cwd().
...
So, you can just set that option and specify the api directory:
const bat = cp.exec("python app.py", {
cwd: path.join(process.cwd(), "api")
});