You need to read the documentation, you are not using fs module correctly.

Here is corrected call from example: https://gist.github.com/2279298

On Sun, Apr 1, 2012 at 3:53 PM, Matthew Hazlett <[email protected]> wrote:

> Unfortunately, that did not solve the problem.
>
> I posted my code and its output / error in Paste Bucket so you can see
> http://www.pastebucket.com/1968
>
>   Charlie McConnell <[email protected]>
>  Sunday, April 01, 2012 6:18 PM
> did you just leave out the callback to your fs.writeFile, or did you not
> provide one?  If you're using fs.readFile - an asynchronous method - and
> not providing a callback, that whole thing will be a race condition for
> you.  Either use fs.readFileSync, or provide a callback and don't try to
> access the file until the callback.
>
>
>
>
> --
> Charlie McConnell
> Head of Support
> Nodejitsu, Inc.
> [email protected]
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>   Matthew Hazlett <[email protected]>
>  Sunday, April 01, 2012 6:14 PM
> It already is a string. I just don't get it :-(
>
>   Marak Squires <[email protected]>
>  Sunday, April 01, 2012 6:11 PM
> Maybe try:
>
> JSON.parse(data.toString())
>
> ?
>
>
>
>
> --
> --
> Marak Squires
> Co-founder and Chief Evangelist
> Nodejitsu, Inc.
> [email protected]
>
>  --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>   Matthew Hazlett <[email protected]>
>  Sunday, April 01, 2012 6:09 PM
>  I have traced the error to the JSON statement.
>
> when I return JSON.parse(data) ; it blows up with an unexpected end of
> file.
>
> When I console.log(JSON.parse(data)); it works fine.  I'm confused!
>
>
>
>   Matthew Hazlett <[email protected]>
>  Sunday, April 01, 2012 4:25 PM
> This throws an error unexpected end of file.
>
>         fs.readFile(__dirname + '/' + filename, function (err, data) {
>                 if (err) throw err;
>                 console.log(data);
>         });
>
> This is a oneline file created by:
>
>         fs.writeFile(__dirname + '/' + filename, JSON.stringify(data));
>
> The file exists and the permissions are fine. Whats wrong?
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
>
> --
>
>  *Matthew Hazlett** Owner**, Clarity Computers*
> Tel: 603 707 1774 | Mobile: 603 707 1774
> [email protected] | http://www.linkedin.com/in/hazlema
>
>
> [image: Facebook] <http://www.facebook.com/profile.php?id=1491561960> [image:
> Twitter] <https://twitter.com/#%21/hazlema> [image: 
> LinkedIn]<http://www.linkedin.com/in/hazlema>
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>



-- 
-- 
Marak Squires
Co-founder and Chief Evangelist
Nodejitsu, Inc.
[email protected]

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

<<postbox-contact.jpg>>

<<twitter.png>>

<<linkedin.png>>

<<postbox-contact.jpg>>

<<facebook.png>>

<<postbox-contact.jpg>>

Reply via email to