javascript - Code works when running node console but not when invoking node <app_name.js> -
i'm using:
npm install babyparse --save
when invoking
node
in terminal (os x yosemite), run following commands , see output:
> var baby = require('babyparse'); undefined > var fs_test_data = baby.parsefiles('fs_test.csv'); undefined > var rows = fs_test_data.data; undefined > rows.foreach(function(element, index, array){ ... console.log(element); ... console.log(index); ... }); [ '3000', ' 1000', ' 2000', ' 30', ' 0', ' 1', '' ] 0 [ '3000', ' 1000', ' 2000', ' 40', ' 0', ' 5', '' ] 1 undefined >
that's great! works!
but....
//test_babyparse.js var baby = require('babyparse'); var fs_test_data = baby.parsefiles('fs_test.csv'); var rows = fs_test_data.data; rows.foreach(function(element, index, array){ console.log(element); console.log(index); });
and running
node test_babyparse.js
ends showing nothing. why? have io , event loop?
thanks,
zakiir
edit: i'm using babyparse.js file found on github, not .js file found on npm not have parsefiles function.
phew!
so yes, looked through source of babyparse.js file , noticed 'fs' not defined.
i wrote
fs = require('fs');
in test_babyparse.js, believe sets 'fs' in global scope.
it worked!
edit: apparently it's not practice add things global scope that, added
var fs = require('fs');
in babyparse.js file.
Comments
Post a Comment