Skip to content

Instantly share code, notes, and snippets.

@easierbycode
Created November 5, 2015 16:58
Show Gist options
  • Save easierbycode/7d860737da86a0a198a1 to your computer and use it in GitHub Desktop.
Save easierbycode/7d860737da86a0a198a1 to your computer and use it in GitHub Desktop.
var fs = require("fs");
var fileName = "foo.txt";
fs.exists(fileName, function(exists) {
if (exists) {
fs.stat(fileName, function(error, stats) {
fs.open(fileName, "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