title: How to process requests in Python through an Express server
body: <p>My approach has been to write a <code>Flask</code> server in Python and forward the request to that.</p>
  <p>Demo.py</p>
  <pre><code>from flask import Flask
  
  app= Flask(__name__)
  
  @app.route(&quot;/&quot;)
  def index():
      return &quot;Hello World&quot;
  
  if __name__ == '__main__':
      app.run(debug=True)
  </code></pre>
  <p>Alternately, I also tried directly invoking a <code>python</code> script and then collecting the result from <code>stdout</code>.</p>
  <p>Trial.js</p>
  <pre><code>const express = require('express')
  const app = express()
  
  app.get('/', (req, res) =&gt; {
  
      const { spawn } = require('child_process');
      const pyProg = spawn('python', ['C:/Users/Selectigence/PycharmProjects/jobapplicationbot/Sample3.py']);
  
      pyProg.stdout.on('data', function(data) {
  
          console.log(data.toString());
          res.write(data);
          res.end('end');
      });
  })
  
  app.listen(4000, () =&gt; console.log('Application listening on port 4000!'))
  </code></pre>