11/3/2017 - 4:24 PM

NodeJS - fs module commands

//fs.readFileSync reads an external file synchronously (blocks code below it). Parameters are the file name and the charset.
var readMe = fs.readFileSync('readMe.txt', 'utf8');

//fs.writeFileSync writes an external files synchronously. Paramenters are the file name and the file content.
fs.writeFileSync('writeMe.txt', 'readMe');

//fs.readFile reads an external file asynchronously(non blocking code). Parameters are the file name, the charset and a call back function(err, data)
fs.readFile('readMe.txt', 'utf8', function(err, data){

//fs.unlink('') deletes and external file. Paremeters are the file name