count file lines in typescript

The solution for “count file lines in typescript” can be found here. The following code will assist you in solving the problem.

‘use strict’;

import * as fs from ‘fs’;

function linesNumber(fileName: string): number {
try {
let fileLines = fs.readFileSync(fileName, ‘utf-8’).split(‘\n’);
return fileLines.length;
} catch (err) {
return 0;
}
}
console.log(linesNumber(‘my-file.txt’))

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

0
inline scripts encapsulated in