[nodejs] Re: fs.read

2012-04-01 Thread Roly Fentanes
I don't see a callback on your `writeFile`. are you sure there's no race condition? On Sunday, April 1, 2012 1:25:29 PM UTC-7, Matthew Hazlett wrote: > > This throws an error unexpected end of file. > > fs.readFile(__dirname + '/' + filename, function (err, data) { > if (e

[nodejs] Re: fs.read

2012-04-01 Thread Bruno Jouhier
fs.writeFile is asynchronous. You need to pass a callback and read the file from the callback: fs.writeFile(__dirname + '/' + filename, JSON.stringify(data), function(err) { if (err) cb(err); fs.readFile(__dirname + '/' + filename, function (err, data) { if (err) cb(err);

Re: [nodejs] Re: fs.read

2012-04-01 Thread Matthew Hazlett
During testing I comment out creating the file and just try reading it. Is the JSON.parse async? Does it have a callback function? This only gives you the key/value pairs while its parsing JSON.parse(function (k,v){}); Roly Fentanes Sunday, April 01, 2012 6:17 PM I