title: How to pass object from one file to another in javascript?
body: <p>I have node js server file (index.js) and client file (orderlist.js)
  In index.js i am getting promise object , like that</p>
  <pre><code>function returnOrderArray() {
      var i = 0;
      const promise = new Promise((resolve, reject) =&gt; {
          connection.query('SELECT * FROM orders', function(error, results) {
              while (i &lt; results.length) {
  
                  order.id[i] = results[i].id;
                  order.wavetype[i] = results[i].wavetype;
                  order.color[i] = results[i].color;
                  order.thick[i] = results[i].thick;
                  order.readydate[i] = results[i].readydate;
                  order.createdate[i] = results[i].createdate;
                  order.manager[i] = results[i].manager;
  
                  i++;
              }
              resolve(order);
              // console.log(order);
  
  
          });
      });
      return promise;
  }
  </code></pre>
  <p>then i want to pass it to other js file.
  I tried to do that with module.exports</p>
  <pre><code>app.get('/orderlist', checkUserSession, async function(request, response) {
      returnOrderArray().catch(error =&gt; console.log(error)).then((() =&gt; {
          module.exports.order = order;
          response.render(&quot;orderlist.ejs&quot;, { username: request.session.username });
      })).catch(error =&gt; console.log(error));
  });
  </code></pre>
  <p>and then import it in orderlist.js</p>
  <pre><code>var ind = require('../../index')
  
  
  function asd() {
      alert(ind.order);
  }
  </code></pre>
  <p>but it seems not to work.</p>
  <p><strong>What am i doing wrong , and what's the best way to pass objects to other files in js?</strong></p>
  <p>oh , and file architecture</p>
  <p><a href="https://i.stack.imgur.com/xZdsx.png" rel="nofollow noreferrer">filearch</a></p>