node.js fs.readFile not working in Windows

Go To StackoverFlow.com

0

Right now I am on an XP box, but this is the same thing on Vista.

I am using node.js v 0.6.14

the following does not work:

var fs = require("fs");
fs.readFile(filename, "utf8", function(err, data) { ... } );

I do NOT get anything in err, but data contains the following:

'{' is not recognized as an internal or external command, operable program or batch file.

If I remove the encoding parameter, then I do get the raw buffer data back. Is this a known issue on the Windows port of node or am I completely missing something? If it is a known issue, are there any good workarounds?

2012-04-04 16:59
by Mark Lybrand


3

What kind of file is it? I created a text file named "text.txt" with the contents of "this is a text file".

I don't have an XP VM handy, but this worked fine for me in node 0.6.9:

var fs = require("fs");

fs.readFile("text.txt","utf8",function(err,data){
    console.log("err: " + err);
    console.log(data);
});

with output of:

err: null
this is a text file
2012-04-04 18:14
by Seth
HTML5. Nothing special. What OS were you using? I will try a text file and see what happens - Mark Lybrand 2012-04-04 21:49
Mine also worked with text.txt... curiouser and curiouser. Now, I did have my text.txt file in the same directory where I was running node. Next thing I will try is moving the html file I was trying to process into the same directory and see if that works - Mark Lybrand 2012-04-04 23:54
Yep. That works too. So, must be something about the paths I am using to reference the files - Mark Lybrand 2012-04-05 00:02
Now, it is working at the other location too?? Back to the drawing board, I think. I think I have bigger problems. I am going to close this question. Sorry for bothering - Mark Lybrand 2012-04-05 00:05
Well, I "would" close it, but I am not worthy : - Mark Lybrand 2012-04-05 00:05
@MarkLybrand mind accepting my answer since it pointed you in the right direction? : - Seth 2012-04-05 04:45
Done and done. : - Mark Lybrand 2012-04-05 14:43
Ads