Skip to content

Instantly share code, notes, and snippets.

@receptor
Created May 24, 2015 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save receptor/9b181868916292da79a7 to your computer and use it in GitHub Desktop.
Save receptor/9b181868916292da79a7 to your computer and use it in GitHub Desktop.
Node.js fs.read
fs.exists(file, function (exists)
{
if (exists)
{
fs.stat(file, function (error, stats)
{
fs.open(file, "r", function (error, fd)
{
var buffer = new Buffer(stats.size);
fs.read(fd, buffer, 0, buffer.length, null, function (error, bytesRead, buffer)
{
var data = buffer.toString("utf8", 0, buffer.length);
console.log(data);
fs.close(fd);
});
});
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment