вы можете запустить python virtual environment
внутри nodejs, вам нужно вызвать python environment из bin
каталога, в котором вы устанавливаете python виртуальную среду, а затем вы можете использовать child_process
для запуска python кода внутри nodejs, см. Этот пример:
const express = require('express')
const app = express()
app.get('/', (req, res) => {
const { spawn } = require('child_process');
const pyProg = spawn('~/py3env/bin/python', ['test.py']);
pyProg.stdout.on('data', function(data) {
console.log(data.toString());
res.write(data);
res.end('end');
});
})
app.listen(3000, () => console.log('listening on port 3000'))
даже вы можете запустить командную строку с помощью shell js, и в этот момент вы можете запустить pm2 : см. это:
const shell = require('shelljs');
shell.exec('pm2 start test.py --interpreter=./py3env/bin/python', function(code, output) {
console.log('Exit code:', code);
console.log('Program output:', output);
});