title: Pass req,res from index.js to another js file in Node
body: <p>[I am using express for node].</p>
  <p>I encountered a code where the form-data is being posted into <code>index.js</code> but it has to be processed in another javascript file. I debugged the original code at nearly every step but at this point I am stuck.</p>
  <p>Here are the relevant parts in the files.</p>
  <p><code>index.js</code></p>
  <pre><code>var express = require('express');
  var router = express.Router();
  const proctor = require('../controllers/proctor');
  
  router.post('/myform', function(req, res, next) {
    console.log(&quot;hello&quot;);
    proctor.function1;
  });
  module.exports = router;
  </code></pre>
  <p><code>proctor.js</code> (not written by me)</p>
  <pre><code>exports.function1 = (req, res) =&gt; {
      console.log(req.body);
  }
  </code></pre>
  <p><code>app.js</code></p>
  <pre><code>var indexRouter = require('./server/routes/index');
  app.use('/', indexRouter);
  module.exports = app;
  </code></pre>
  <p>So, console shows &quot;hello&quot;, but not the <code>req.body</code> so the second js file is not being called at all. The <code>proctor.js</code> is not my code and I think I need to import <code>index.js</code> maybe to get it working.</p>
  <p>The file tree is</p>
  <pre><code>app.js
  server
     controllers
        proctor.js
     routes
        index.js
  </code></pre>