sloc is a simple, fast tool for counting lines of code that’s designed to be used from both the command line and Node.js scripts. It tallies physical lines, source lines, comment lines, and blank lines, giving you a quick snapshot of code size across files or entire directories. The utility is language-aware through lightweight detectors and patterns, so it can ignore comments correctly and avoid counting generated or minified files if you configure it to. Output can be human-readable for quick checks or machine-readable (like JSON) for CI pipelines that track repository growth over time. It supports typical developer conveniences such as glob patterns, file/directory ignores, and sensible defaults so you can drop it into existing workflows without fuss. Teams often wire sloc into build steps to watch trends, compare modules, or enforce thresholds before merging changes, making it a handy maintenance metric rather than a vanity number.
Features
- Counts physical lines, source code lines, single-line comments, block comments, mixed source/comment lines, and empty lines
- Detects lines containing TODOs
- Outputs results as plain table, CSV, or JSON
- Can be used via CLI or as a Node.js module in projects
- Installable globally (npm install -g sloc) or locally as a dependency
- Lightweight and streamlines SLOC analysis