Skip to content

Read File in Node.js

iterion edited this page Oct 19, 2010 · 1 revision
var sys = require("sys"), fs = require("fs");
fs.open(filename, "r", 0666, function (err, fd) {
  if (er) throw er;
  (function reader () {
    fs.read(fd, 1024, "ascii", function (er, chunk) {
      if (er) throw er;
      sys.debug(chunk);
      if (chunk) reader();
    });
  })(); // reader()
});
Clone this wiki locally