I
I
ikysu2018-07-23 00:22:21
JavaScript
ikysu, 2018-07-23 00:22:21

Node.js - How to count lines in a file?

On hand there are files with a text format. How to count the number of lines in a file using Node.js?
ps I also forgot to say that the number should be one, not several numbers.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stockholm Syndrome, 2018-07-23
@ikysu

const fs = require('fs');
const data = fs.readFileSync('text.txt').toString();
console.log(data.split('\n').length);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question