count file lines in typescript

Solutions on MaxInterview for count file lines in typescript by the best coders in the world

showing results for - "count file lines in typescript"
Diego
05 May 2020
1'use strict';
2
3import * as fs from 'fs';
4
5function linesNumber(fileName: string): number {
6  try {
7    let fileLines = fs.readFileSync(fileName, 'utf-8').split('\n');
8    return fileLines.length;
9  } catch (err) {
10    return 0;
11  }
12}
13console.log(linesNumber('my-file.txt'))