I have a several processes node.js. I want to only add one string to one file in each request ( like log file in nginx, apache, etc ). What is the best way do it ?
Simple:
fs.open(file, "a", 0744, function (err, fd) {
if (err) throw err;
fs.write(fd, data, null, 'utf8', function (err, written) {
if (err) throw err;
});
});
or else ?
This will work, however it may not be the best solution if it is constantly opening and closing the file. For something with quicker writes I would try benchmarking it against fs.createWriteStream, especially because this gives you a scope you can use in routes.