Skip to content

Instantly share code, notes, and snippets.

@stafordtituss
Created March 4, 2020 04:38
Show Gist options
  • Save stafordtituss/b4a69e91d810710c2c8fd51347a08d1e to your computer and use it in GitHub Desktop.
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 >
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