Changeset 36329 for other-projects
- Timestamp:
- 2022-07-28T23:47:09+12:00 (21 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/bib-stinky/trunk/nodejs-server/express-web-server.js
r36315 r36329 1 1 // Setup Express 2 const path = require('path') 2 const path = require('path'); 3 const { spawn } = require('child_process'); 4 3 5 const express = require("express"); 4 6 const cors = require("cors"); 7 5 8 6 9 const app = express(); … … 25 28 26 29 30 app.get("/python-test", (req, res) => { 31 32 var dataToSend; 33 34 // Spawn new child process to call the python script 35 const python = spawn('python3', ['script1.py']); 36 37 // Collect data from script 38 python.stdout.on('data', function (data) { 39 console.log('Pipe data from python script ...'); 40 dataToSend = data.toString(); 41 }); 42 43 // In close event we are sure that stream from child process is closed 44 python.on('close', (code) => { 45 console.log(`child process close all stdio with code ${code}`); 46 47 res.send(dataToSend) 48 }); 49 }); 50 51 27 52 app.listen(port, () => { 28 53 console.log(`Started CORS-enabled Express web server running on port ${port}.`);
Note:
See TracChangeset
for help on using the changeset viewer.