Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

count file lines in typescript

'use strict';

import * as fs from 'fs';

function linesNumber(fileName: string): number {
  try {
    let fileLines = fs.readFileSync(fileName, 'utf-8').split('
');
    return fileLines.length;
  } catch (err) {
    return 0;
  }
}
console.log(linesNumber('my-file.txt'))
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #count #file #lines #typescript
ADD COMMENT
Topic
Name
9+4 =