FS Module

// FS MODULE

var fs = require('fs');

// write a file using fs
var myText = 'This is a sample statement';
fs.writeFileSync('anything.txt', myText);


// read a file
fs.readFile('./anything.txt', function(err, data){
    if(err){
        console.error('Error is ' + err);
    } else {
        console.log(data.toString());
    }
});

// delete a file
fs.unlink('./anything.txt', function(err){
    if(err){
        console.error('Error message: ' + err);
    } else {
        console.log('The file was successfully deleted.');
    }
});

Comments

Popular posts from this blog

Lesson 2 Chat

Arrays