Skip to content

Instantly share code, notes, and snippets.

@polotek
Created April 24, 2010 15:53
Show Gist options
  • Save polotek/377732 to your computer and use it in GitHub Desktop.
Save polotek/377732 to your computer and use it in GitHub Desktop.
/*
* Simple example of using fs methods to append to a file
*/
var sys = require('sys'),
fs = require('fs');
fs.open('my.log', 'a', undefined, function(err, fd) {
if(err) throw err;
fs.write(fd, 'Appending to this file\n', undefined, undefined, function(err, written) {
if(err) throw err;
sys.puts(written + ' bytes written');
fs.close(fd, function(err) {
if(err) throw err;
fs.readFile('my.log', function(err, data) {
if(err) throw err;
sys.puts(data);
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment