Created
March 4, 2020 04:38
-
-
Save stafordtituss/b4a69e91d810710c2c8fd51347a08d1e to your computer and use it in GitHub Desktop.
HTTP Readable Stream using fetch - SERVER SIDE (NodeJS) < An example for getting artillery report stream >
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
const express = require("express"); | |
const bodyParser = require("body-parser"); | |
const app = express(); | |
const {exec} = require('child_process'); | |
var data1; | |
var FetchStream = require("fetch").FetchStream; | |
const { spawn } = require("child_process"); | |
app.use(express.static('public')); | |
app.use(bodyParser.urlencoded({ extended: true })); | |
app.set('view engine','ejs') | |
app.get('/',function(req,res){ | |
res.render('artillery'); | |
}); | |
app.post('/',function(req,res){ | |
return new Promise( | |
(resolve, reject) => { | |
const process = exec("artillery run config_artillery.yml -o report.json && artillery report report.json"); | |
const [/* stdin */, stdout, stderr] = process.stdio; | |
stdout | |
.on("data", function (chunk) { | |
console.log(chunk.toString()); | |
data1 = chunk.toString(); | |
res.write(data1); | |
}) | |
.on("error", function (err) { | |
console.error(err); | |
reject(err); | |
}) | |
.on("close", () => resolve()) | |
.on("end", () => resolve()); | |
stderr | |
.on("data", function (chunk) { | |
console.log(chunk.toString()); | |
}) | |
.on("error", function (err) { | |
console.error(err); | |
}) | |
.on("close", () => resolve()) | |
.on("end", () => resolve()); | |
}) | |
.then(() => { | |
res.end(); | |
console.log(`Completed Artillery Report!!`);}) | |
.catch(console.error); | |
}); | |
app.listen(8000); | |
console.log('listen'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment