I want to run a python script from nodejs application, a simple python script. So I need to add support so that from nodejs I can do something like:
app.get('/', (req, res) => {
var dataToSend;
// spawn new child process to call the python script
const python = spawn('python', ['script1.py']);
// collect data from script
python.stdout.on('data', function (data) {
console.log('Pipe data from python script ...');
dataToSend = data.toString();
});
// in close event we are sure that stream from child process is closed
python.on('close', (code) => {
console.log(`child process close all stdio with code ${code}`);
// send data to browser
res.send(dataToSend)
});
});
below is my snapcraft.yaml file
version: '1.0'
summary: Sample snap
description: |
Desc
base: core20
grade: devel
confinement: devmode
parts:
sample-express:
plugin: npm
npm-node-version: 15.13.0
source: .
apps:
sample-express:
command: bin/sample-express
Any help in this regard will be awesome! Thanks.