How to quickly count (source) lines of code using npx cloc

Published on in npm

Last updated on

Run npx cloc [options] <files/dirs>. E.g. npx cloc src/ or npx cloc foo.js bar.css.

The cloc npm package by Kent C. Dodds is a wrapper around the cloc command line program by Al Danial.

Example from this repo:

$ npx cloc . \
--exclude-dir=_sample-content,_site,node_modules \
--not-match-f=package-lock.json

npx: installed 1 in 1.085s
172 text files.
162 unique files.
49 files ignored.

github.com/AlDanial/cloc v 1.90 T=0.22 s (707.6 files/s, 59215.9 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
Markdown 100 1947 0 8129
JavaScript 27 114 110 848
Pug 18 78 123 789
CSS 1 34 31 328
TOML 1 31 2 127
JSON 2 0 0 67
YAML 1 2 2 12
XML 1 0 0 8
Bourne Shell 1 4 9 7
SVG 1 0 0 1
-------------------------------------------------------------------------------
SUM: 153 2210 277 10316
-------------------------------------------------------------------------------

Run npx cloc or npx cloc --help for more options and information.