Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // we will use sys.log for logging
- var sys = require('sys');
- // send open file command, with callback
- fs.open('path/to/file.js', 'w', 0777, function(err, fd) {
- //throw error, if there was one
- if (err) throw err;
- // send write command with opened file, content, starting point, encoding and callback
- fs.write(fd, 'Hello World!', 0, 'utf8', function (err, written) {
- //throw error, if there was one
- if (err) throw err;
- // after successful file write, log number of bytes written
- sys.log('Success! Wrote ' + written + ' bytes');
- });
- });
Add Comment
Please, Sign In to add comment