Created
June 19, 2014 00:30
-
-
Save johnelliott/8dac3894f9bed9f66037 to your computer and use it in GitHub Desktop.
Node File System (fs)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// File I/O is provided by simple wrappers around standard POSIX functions. To use this module do require('fs'). All the methods have asynchronous and synchronous forms. | |
// Watch for changes on filename. The callback listener will be called each time the file is accessed. | |
fs.watch('myfile.txt', function (event, filename) { | |
// fs.readFile asynchronously reads the entire contents of a file. | |
fs.readFile(file, {encoding:'utf8'}, function ( err, data ) { | |
if (err) throw err; | |
console.log(data); | |
}); | |
}); | |
// write out our file | |
// . . . and see what changes | |
fs.writeFile(file, "Hello NodeDC!"); | |
setTimeout( function() { | |
fs.writeFile(file, "Hello NodeDC!"); | |
}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment