title: module.exports return value undefined
body: <p>Little info, i have an arp.js file which takes a subnet address "192.168.2" and gets all strings returned from arp -a and stores in an array.</p>
  
  <p>I can't figure out why my arpList function is returning an undefined value in my index.js file.</p>
  
  <p>All the console.logs are returning the correct values in the arp.js page when called from the index.js, but the ipObj is coming up undefined. Even the console.log before i return of ipObj works.</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <pre><code>var { spawn } = require('child_process');
  const arpLs = spawn('arp', ['-a']);
  var bufferData;
  
  
  module.exports = {
      arpList: function (subnet) {
  
  
          arpLs.stdout.on('data', data =&gt; {
              bufferData += data
          })
  
  
          arpLs.stderr.on('data', data =&gt; {
              console.log('error: ' + data);
          });
  
  
          arpLs.on('exit', function (code) {
              if (code != 0) {
                  console.log("Error exiting"); //if error occurs
              }
              console.log("exit start 1"); // checking internal processes at stages
              var dataArray = bufferData.split(' ');
              var ipArray = [];
              for (i = 0; i &lt; dataArray.length; i++) {
                  if (dataArray[i].includes(subnet)) {
                      ipArray.push(dataArray[i]);
                      console.log("loop working");
                  }
              }
              var ipObj = { "lanIps": ipArray };
              console.log("Object is there: "+ipObj)
              return ipObj; // this obj should be returned to the index.js call using 
          })
      },
      sayMyName: function () {
          return "Hello";
      }
  }
  
  //arpList(ipSubnet);
  //INDEX.js
  //the index page looks like this
  //var arp = require('./arp.js);
  //var ipSubnet = "192.168.2";
  
  //var lanIps = arp.arpList(ipSubnet);
  //console.log(lanIps);
  </code></pre>
  
  <p>I ended up adding a callback function to arpList - function (subnet, callback)</p>
  
  <p>Then instead of returning the value pass it into the callback</p>
  
  <p>Then on the index.js side instead of </p>
  
  <pre><code>var lanIps = arp.arpList(value)
  </code></pre>
  
  <p>i used</p>
  
  <pre><code>arp.arpList(value, function(res){lanIps = res}
  </code></pre>