NodeJS export async variable with module.exports
<p>I have 2 files in a nodejs app: </p>

<p><strong>export.js</strong> (reads a file line by line and saves it into an array)</p>

<pre><code>var lineReader = require('readline').createInterface({
  input: require('fs').createReadStream('test.txt')
});
var file_lines = [];

onFinish(function(result) {
    module.exports = result;
});

function onFinish(callback){
    lineReader.on('line', function (line) {

        file_lines.push(line);

    }).on('close', function() {
        callback(file_lines);
    })
};
</code></pre>

<p>and <strong>app.js</strong> (should get the exported values so I can play with it in here)</p>

<pre><code>var a = require("./export");

console.log(a);
</code></pre>

<p>As you can see in the <strong>export.js</strong> I've used an async callback so it will save the data, but I think I'll need another async callback in the <strong>app.js</strong> file. What would be the best way to achieve this?</p>

<p>P.S. I realized that the async call for the <strong>export.js</strong> file isn't necessary. Here is the new version:</p>

<pre><code>var lineReader = require('readline').createInterface({
  input: require('fs').createReadStream('test.txt')
});
var file_lines = [];

lineReader.on('line', function (line) {

    file_lines.push(line);

}).on('close', function() {
    module.exports = file_lines;
    console.log(file_lines);
})
</code></pre>

<p>But again, my question will be, how would I get the values in the a variable in the <strong>app.js</strong> file?</p>