Created
May 11, 2020 21:46
-
-
Save JoeThunyathep/ea0713caa129208d7e1a029a35dd44ae to your computer and use it in GitHub Desktop.
NodeJS server with Spawning Python Process
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Part1: Express Web Server | |
var express = require('express'); | |
var app = express(); | |
var port = 3000; | |
app.listen(port, function () { | |
console.log(`server running on http://localhost:${port}`); | |
console.log(`Try Getting Aggregated COVID19 data at http://localhost:${port}/covid_19_timeseries?numberOfCountries=3&aggregationInterval=W`); | |
}) | |
//Part2: Express Get Request for Covid-19 Time Series data | |
app.get('/covid_19_timeseries', function (req, res) { | |
var spawn = require('child_process').spawn; | |
var process = spawn('python', ['./covid19aggregator.py', | |
req.query.numberOfCountries, // for example ~ 3 | |
req.query.aggregationInterval // for example ~ W for Week | |
] | |
); | |
process.stdout.on('data', function (data) { | |
res.send(data.toString()); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment