I am trying to read a file in node.js but I am getting tired of writing so many callbacks. Is there a way I can just read a file in one line?
2 Answers
Callbacks are king, but you can use anonymous callbacks...
fs.readFile('/etc/passwd', function (err, data) {
if (err) throw err;
console.log(data);
});
http://nodejs.org/api/fs.html#fs_fs_readfile_filename_options_callback
filedata = require('fs').readFileSync(filename);will do.