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;

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

More questions on [categories-list]

inline scripts encapsulated in