node.js - Global variable in javascript function -



node.js - Global variable in javascript function -

this code:

var csv = require('csv'); var loader = function() { var rows; csv() .from.path('./data/ebay.csv', { columns: true, delimiter: ';' }) .to.array( function(rows) { setrows(rows); }); function setrows(input) { rows = input; } homecoming rows; }; module.exports = loader;

i want rows when phone call loader object. i'am beginner in oop javascript, have no thought it. start learning javascript oop node? found many tutorials describe how start node , how create webs using various frameworks, know. programmed in php , moving nodejs , i'm wasted.

like node.js functions deal i/o csv works asynchronously. therefore, phone call csv.from..to.. returns immediately, callback function called later. create loader asynchronous well, this:

var csv = require('csv'); var loader = function(ondata) { csv() .from.path('./data/ebay.csv', { columns: true, delimiter: ';' }) .to.array(ondata); }; module.exports = loader;

javascript node.js oop

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -