I want to do this. But I am not able to run all of this synchronously. Every step is executing all at once. Can anyone help?
I need to do this backend task in Node.js express.
Step 1: Enter the keyword from the front end(written in react)
Step 2: Run the command: " shell.exec(__dirname + /run.sh "${data}"
); " at the backend. [[data is the keyword received from the front end]]. It will search the keyword in my file and generate a csv file.
Step 3: Run a python script which will execute a python file(csv_to_html.py) after completion of Step 2 execution. It will convert the csv file generated to html table and create a output.html file
Step 4: On completion of step 3, an output.html file will be generated. Send this file in an iframe on the front screen(index.html or index.ejs or index.hbs) below the search box. Suggestions are welcome on how can I display it on the frontend.
All this should be done dynamically.
This is what I have done:
const { response } = require("express");
const express = require("express");
const bodyParser = require("body-parser");
const shell = require("shelljs");
const app = express();
const spawn = require("child_process").spawn;
app.use(express.static("public"));
app.use(bodyParser.urlencoded({ extended: true }));
var data = "";
app.get("/", function (req, res) {
shell.exec(__dirname + `/run.sh "${data}"`);
const pythonProcess = spawn('python', ["csv_to_html.py"]);
res.sendFile(__dirname + "/index.html");
});
app.post("/", function (req, res) {
data = req.body.load_data;
res.redirect("/"));
});
app.listen(3000, function () {
console.log("Starting server at port 3000...");
});