An Interest In:
Web News this Week
- April 19, 2024
- April 18, 2024
- April 17, 2024
- April 16, 2024
- April 15, 2024
- April 14, 2024
- April 13, 2024
May 20, 2021 04:19 am GMT
Original Link: https://dev.to/rajeshkumaryadavdotcom/node-js-determining-the-line-count-of-a-text-file-195l
Node.js : Determining the line count of a text file
Create a new file as app.js and paste below code -
app.js
const readline = require('readline');const fs = require('fs');var file = 'path.to.file';var linesCount = 0;var rl = readline.createInterface({ input: fs.createReadStream(file), output: process.stdout, terminal: false});rl.on('line', function (line) { linesCount++; // on each linebreak, add +1 to 'linesCount'});rl.on('close', function () { console.log(linesCount); // print the result when the 'close' event is called});
Run below command -
node app.js
You will get the line count of text file.
With all that being said, I highly recommend you keep learning!
Thank you for reading this article. Please feel free to connect with me on LinkedIn and Twitter.
Original Link: https://dev.to/rajeshkumaryadavdotcom/node-js-determining-the-line-count-of-a-text-file-195l
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To