Slip 14 - A) Create a Node.js Application to search a particular word in a file and display result on console.

 Solution:

search_word.js

var fs=require('fs');

fs.readFile('C:/Users/Public/node_prog/searchf.txt', function (err, data) {

  if (err) throw err;

  if(data.includes('dfgdf')){

   console.log(data.toString())

  }

else

{

  console.log('word not found');

}

});

 

Initiate search_word.js:

C:\Users\Your Name>node search_word.js

Post a Comment

0 Comments