I am using a node server to run python scripts. I am using the Python shell package to run them and this works fine. Here it is in the server.js file that I am running:
app.get('/start/:fileName', function(req, res) {
let fileName = req.params.fileName;
console.log(fileName)
PythonShell.run(`./python_scripts/${fileName}`, function (err,results) {
console.log('results ',results);
if (err) throw err;
console.log('finished');
});
});
In another file main.js I have the command:
function fetchStartEndpoint(fileName) {
fetch(`/start/${fileName}`)
.catch(error => console.log(error));
}``
And I call fetchStartEndpoint when a button is clicked.
This all works fine but I want to use multiple buttons to run multiple scripts. When I click the button a script runs, but when I click a different button to run a different script, the first one continues to run. I want it to end and run the second one. Is there a way to override the initial script and run the second one instead of other than restarting the server?