go over each line in text nodejs 1

go over each line in text nodejs

require('fs'). readFileSync('file.txt', 'utf-8'). split(/\r?\n/). forEach(function(line){
  console. log(line);
})

Here is what the above code is Doing:
1. It’s using the require function to load the fs module.
2. It’s using the readFileSync function to read the contents of the file.txt file.
3. It’s using the split function to split the contents of the file into an array of lines.
4. It’s using the forEach function to loop through the array of lines.
5. It’s using the log function to print each line to the console.

Similar Posts