2
I wish to count the number of new lines of a file. For this I am doing as follows the reading of the file :
const fs = require('fs')//utilizando o módulo fs
fs.readFileSync('<caminhoParaoPrograma>/programa.js')//leitura do arquivo desejado
From this reading of the file, I need a logic to identify the character '\n' and count the total of these in the file. How can I fix this?
Obg for the answer! There was a small error in this solution when using 'const Matches = Contents.match(/ n/g)'. The following error has been returned: 'Typeerror: Contents.match is not a Function'. What can be done to resolve it? Thanks in advance!
– Gabriel Ribeiro Carneiro
contents
must be astring
for the code to work. You must make sure your file is being treated as a string before doing so.– Luiz Felipe