Reading files from a directory inside a meteor app

This works for me in Meteor 1.0:

var fs = Npm.require('fs')
var xsd = fs.readFileSync(process.cwd().split('.meteor')[0] + 'server/company.xsd', 'utf8')

I learned that it is best to upload files in your private folder if you are not displaying them outside. In my case I need to store XML uploads and process them. At first I wrote the XML into the public folder but that would trigger a reload. Then I renamed the the upload folder to /public/.#uploads which would stop the reload of Meteor, but then again...it completely ignored that folder during build and the uploaded folder would not exist in the build (throw ENOENT error during read).

So I figured out it is best to put the files in /private/files and then reading goes as follows:

result = fs.readdirSync('assets/app/files')

Everything in the private folder will be moved to the Assets folder where during runtime there is an APP folder available (you do not see that in your build folder structure).

It helps to just simple dump result = fs.readdirSync('.') to see what folder you in and look through the structure.

***UPDATE***** Locally putting files in private folder still triggered meteor rebuild/update (perhaps not in production..) so I found another solution using the UploadServer just to define the upload directory: https://github.com/tomitrescak/meteor-uploads

Tags:

Node.Js

Meteor