NodeJS File IO
Read and write files with NodeJS
Read Files
non-blocking
#!/usr/bin/node
// non-blocking
var fs = require( 'fs' );
console.log( "non-blocking" );
fs.readFile( "test.txt", "utf8", function( err, data ) {
console.log( data );
});
blocking
#!/usr/bin/node
// blocking
var fs = require( 'fs' );
console.log( "blocking" );
var data = fs.readFileSync( "test.txt", "utf8" );
console.log( data );