title: How to execute commands in backend(Node.js Express) synchronously step by step?
body: <p>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?</p>
  <p>I need to do this backend task in Node.js express.</p>
  <p>Step 1: Enter the keyword from the front end(written in react)</p>
  <p>Step 2: Run the command: &quot; shell.exec(__dirname + <code>/run.sh &quot;${data}&quot;</code>); &quot; 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.</p>
  <p>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</p>
  <p>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.</p>
  <p>All this should be done dynamically.</p>
  <p>This is what I have done:</p>
  <pre><code>    const { response } = require(&quot;express&quot;);
      const express = require(&quot;express&quot;);
      const bodyParser = require(&quot;body-parser&quot;);
      const shell = require(&quot;shelljs&quot;);
  
      const app = express();
      const spawn = require(&quot;child_process&quot;).spawn;
  
      app.use(express.static(&quot;public&quot;));
      app.use(bodyParser.urlencoded({ extended: true }));
      var data = &quot;&quot;;
  
      app.get(&quot;/&quot;, function (req, res) {
        shell.exec(__dirname + `/run.sh &quot;${data}&quot;`);
        const pythonProcess = spawn('python', [&quot;csv_to_html.py&quot;]);
        res.sendFile(__dirname + &quot;/index.html&quot;);
      });
  
      app.post(&quot;/&quot;, function (req, res) {
        data = req.body.load_data;
        res.redirect(&quot;/&quot;));
      });
  
      app.listen(3000, function () {
        console.log(&quot;Starting server at port 3000...&quot;);
      });
  </code></pre>