Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor reading CSV files to populate database don't work after deploy

Tags:

meteor

So I have a bunch of data that I want to load into database from CSV. I've hacked together a solution that works in local development, but when I deploy to meteor.com, it no longer works.

I'm loading the csv file in the folder /server/data/:

function readData(name){
    var fs = __meteor_bootstrap__.require('fs');   
    var path = __meteor_bootstrap__.require('path');   
    var base = path.resolve('.');
    var data = fs.readFileSync(path.join(base, '/server/data/', name));
    return CSVToArray(data);
}

After I deploy to meteor.com, i got:

INFO Error: ENOENT, no such file or directory '/meteor/containers/98eb1286-120b-ee84-8e98-ce673fa2eab7/public/data/categories.csv'
    at Object.openSync (fs.js:240:18)
    at Object.readFileSync (fs.js:128:15)
    at readData (app/server/models.js:10:16)
    at app/server/categories.js:6:7
    at /meteor/containers/98eb1286-120b-ee84-8e98-ce673fa2eab7/bundle/server/server.js:132:63
    at Array.forEach (native)
    at Function.<anonymous> (/meteor/containers/98eb1286-120b-ee84-8e98-ce673fa2eab7/bundle/server/underscore.js:76:11)
    at /meteor/containers/98eb1286-120b-ee84-8e98-ce673fa2eab7/bundle/server/server.js:132:7

Any idea how I can get meteor to see the csv file after deployment?

like image 892
Ricky Gu Avatar asked Aug 28 '12 01:08

Ricky Gu


2 Answers

I realize this question is old, but it still ranks high on certain keyword searches. So, if you're using Meteor 0.6.5+, you can use the new Assets API.

like image 96
0x6A75616E Avatar answered Sep 29 '22 01:09

0x6A75616E


The issue is that meteor only bundles files that it knows about (ie. JS/CSS/HTML/+more depending on which packages you use) up when it deploys.

Try putting the file you need in the public directory (this directory is exempt from the above rule).

like image 36
Tom Coleman Avatar answered Sep 29 '22 01:09

Tom Coleman