Guest User

Untitled

a guest
Jun 25th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. // we will use sys.log for logging
  2. var sys = require('sys');
  3. // send open file command, with callback
  4. fs.open('path/to/file.js', 'w', 0777, function(err, fd) {
  5. //throw error, if there was one
  6. if (err) throw err;
  7. // send write command with opened file, content, starting point, encoding and callback
  8. fs.write(fd, 'Hello World!', 0, 'utf8', function (err, written) {
  9. //throw error, if there was one
  10. if (err) throw err;
  11. // after successful file write, log number of bytes written
  12. sys.log('Success! Wrote ' + written + ' bytes');
  13. });
  14. });
Add Comment
Please, Sign In to add comment