saeed jalali saeed jalali - 1 year ago 164
JSON Question

How to write and read from csv or json file in meteor

I am using papaParse
and I want to save result of this package into file and users can download it. what is the best way to do this? also I am use this node.js code for do it

var csv = Papa.unparse(Users.find().fetch());
console.log("csv : " + JSON.stringify(csv)); // get csv format (not in file)
fs.writeFile("meteorProject/public/", csv, function(err) {
if(err) {
return console.log(err);

console.log("The file was saved!");

but give this error

{ [Error: EISDIR: illegal operation on a directory, open 'meteorProject/public/']
I20160907-13:00:26.970(4.5)? errno: -21,
I20160907-13:00:26.970(4.5)? code: 'EISDIR',
I20160907-13:00:26.970(4.5)? syscall: 'open',
I20160907-13:00:26.970(4.5)? path: 'meteorProject/public/' }

and how can resolve it ??
thanks :-)

Answer Source

This is the issue related to directory please check the directory path you are given here. i.e. - "meteorProject/public/". So what you need to change is just the directory name you are using . As i tried with my directory and its running well. Or i suggest you to try with the fileName.csv as well while saving the file like:- meteorProject/public/test.csv

or just completely change the path of directory like as i tried with my ubuntu machine and its running well.

var userArray = Users.find().fetch();
var data = Papa.unparse(userArray);
console.log("data is....");
        console.log("err while saving");
        console.log("File saved");

The above code save the file in the test folder via test.csv name.

Please check and let me know if you again facing any issue. If you want to know about your error in depth then please see the link:-

Hope this would help!


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download