0% found this document useful (0 votes)
23 views5 pages

Task 1 Blocking: Require Readfilesync Log Tostring

Uploaded by

Anil Navale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views5 pages

Task 1 Blocking: Require Readfilesync Log Tostring

Uploaded by

Anil Navale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Task 1

BLocking

var fs = require("fs");

var data = fs.readFileSync('input.txt');


   
   console.log(data.toString());

console.log("Program Ended");

Output

Task 2
Non - Blocking

var fs = require("fs");

fs.readFile('input.txt', function (err, data) {


   if (err) return console.error(err);
   console.log(data.toString());
});

console.log("Program Ended");

Output

Task 3
Write into File

var fs = require('fs');

fs.writeFile('input.txt', 'May the Node be wit you', function (err) {


  if (err) throw err;
  console.log('Saved!');
});
Output

Task 4

Rename File

var fs = require('fs');

fs.rename('input.txt', 'myrenamedfile.txt', function (err) {


  if (err) throw err;
  console.log('File Renamed!');
});

Output
Task 5
Rename File

var fs = require('fs');

fs.rename('input.txt', 'myrenamedfile.txt', function (err) {


  if (err) throw err;
  console.log('File Renamed!');
});

Output
Task 6

var fs = require('fs');

fs.unlink('myrenamedfile.txt', function (err) {


  if (err) throw err;
  console.log('File deleted!');
});

Output
Conclusion -
Learned about the non-blocking and asynchronous nature of Node and also performed operations
using the file system(fs ) module.

You might also like