Error using Miso.Dataset with URL on node.js
Opened this issue · 1 comments
Deleted user commented
Miso.Dataset works great within the browser, using on Node.js for first time and getting an error. Presumably a newbie error, but looks like the one reported in #193.
Specifically it appears global
is undefined. Was able to create the issue in a new project:
express --sessions miso_test
npm install miso.dataset --save
npm install
- then add following lines at end of app.js:
var Miso = require("miso.dataset");
// this works fine
//var ds = new Miso.Dataset({
// data: [
// { color : "red", r : 255, g : 0, b : 0 },
// { color : "blue", r : 0, g : 0, b : 255 },
// { color : "green", r : 0, g : 255, b : 0 }
//]
//});
// this fails on fetch
var ds = new Miso.Dataset({
url: 'data/MST.csv',
delimiter: ','
}
);
ds.fetch({
success : function() {
console.log("Available Columns:" + this.columnNames());
console.log("There are " + this.length + " rows");
}
});
Stack trace below:
/Users/pieter/Exp/influence/miso_test/node_modules/miso.dataset/dist/node/miso.ds.deps.0.4.1.js:2258
XObject ? new global.ActiveXObject("Microsoft.XMLHTTP") : new global.XMLHttpRe
^
TypeError: undefined is not a function
at Object._xhrSetup.xhr (/Users/pieter/Exp/influence/miso_test/node_modules/miso.dataset/dist/node/miso.ds.deps.0.4.1.js:2258:95)
at Function.Dataset.Xhr (/Users/pieter/Exp/influence/miso_test/node_modules/miso.dataset/dist/node/miso.ds.deps.0.4.1.js:2286:32)
at _.extend.fetch (/Users/pieter/Exp/influence/miso_test/node_modules/miso.dataset/dist/node/miso.ds.deps.0.4.1.js:2242:15)
at _.extend.fetch (/Users/pieter/Exp/influence/miso_test/node_modules/miso.dataset/dist/node/miso.ds.deps.0.4.1.js:1029:21)
at Object.<anonymous> (/Users/pieter/Exp/influence/miso_test/app.js:45:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
Deleted user commented
Reading files and parsing CSV files is a specialty in itself, so delegated that part to node-csv, and all works well.
var Miso = require("miso.dataset");
var csv = require('csv');
csv()
.from.options({columns: true})
.from.path(__dirname+'/../public/data/MST.csv', { delimiter: ',', escape: '"' })
.to.array( function(data){
var ds = new Miso.Dataset({
data: data
});
ds.fetch({
success : function() {
console.log("Dataset Ready. Columns: " + this.columnNames());
console.log("There are " + this.length + " rows");
}
});
});