npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

cli-git-size

v1.0.4

Published

A tool that helps you see the actual size of the project that you have built

Readme

gsize

A simple Node.js CLI tool that scans a project directory and helps you understand which files are taking up space.

Features

  • Scan project files recursively
  • Ignore .git and .gitignore
  • Sort files by size
  • Find the smallest N files
  • Find the largest N files
  • Calculate total project size
  • Display results in a terminal table
  • Format file sizes as Bytes, KB, MB, GB, etc.
  • Output data as JSON
  • Colored terminal output using Chalk

Installation

Install the package globally with npm:

npm install -g cli-git-size

After installation, the CLI command is:

gsize

Usage

Run the command from the directory/project you want to analyze:

gsize

Show help

gsize --help

Sort by size --- ascending

gsize -s

or:

gsize --sortAsc

Sort by size --- descending

gsize -d

or:

gsize --sortDesc

Show the smallest N files

gsize -l 5

or:

gsize --last 5

If no number is provided, the command uses all scanned files.

Show the largest N files

gsize -f 5

or:

gsize --first 5

If no number is provided, the command uses all scanned files.

Show total project size

gsize -t

The result is displayed using a human-readable size such as 10.94 KB, 2.4 MB, etc.

Output as JSON

gsize -j

or:

gsize --json

Options

Option Description


-s, --sortAsc Sort files by size in ascending order -d, --sortDesc Sort files by size in descending order -l, --last [n] Show the smallest N files -f, --first [n] Show the largest N files -t, --totSize Show the total size of the scanned folder -j, --json Show the file data in JSON format -h, --help Show help information

Example

Running:

gsize -f 5

can produce a table similar to:

┌─────┬────────────────────┬─────────┐
│ No. │ File               │ Size    │
├─────┼────────────────────┼─────────┤
│ 1   │ package-lock.json  │ 5.82 KB │
│ 2   │ index.js           │ 1.71 KB │
│ 3   │ Formatter.js       │ 1.44 KB │
│ 4   │ Analyzer.js        │ 1.01 KB │
│ 5   │ Scanner.js         │ 735 B   │
└─────┴────────────────────┴─────────┘

Project Structure

cli-git-size/
├── index.js
├── Scanner.js
├── Analyzer.js
├── Formatter.js
├── package.json
├── package-lock.json
└── README.md

index.js

The CLI entry point.

Responsible for:

  • Defining Commander options
  • Reading user input
  • Calling the scanner
  • Calling analyzer functions
  • Passing results to the formatter
  • Printing the final output

Scanner.js

Responsible for recursively scanning directories and collecting:

{
    path: "path/to/file",
    size: 1234
}

It currently ignores:

.git
.gitignore

Analyzer.js

Contains the analysis functions:

  • sortBySizeA(arr) --- sorts files by size in ascending order
  • sortBySizeD(arr) --- sorts files by size in descending order
  • getBottomN(arr, n) --- returns the smallest N files
  • getBiglN(arr, n) --- returns the largest N files
  • calculateTotalSize(arr) --- calculates the total size of all scanned files

Formatter.js

Responsible for converting analyzed data into user-friendly terminal output.

Current formatter functionality includes:

  • formatBytes(bytes) --- converts bytes into readable units
  • formatSize(arr) --- formats file-size values
  • formatJSON(arr) --- prepares JSON output
  • mkTable(arr) --- creates the terminal table
  • colourSize(...) --- adds color to size output

Architecture

The project follows a simple pipeline:

User
  │
  ▼
index.js
  │
  ▼
Scanner.js
  │
  │  [{ path, size }, ...]
  ▼
Analyzer.js
  │
  │  sorted / filtered / calculated data
  ▼
Formatter.js
  │
  ▼
Terminal Output

This separation keeps scanning, analysis, and presentation logic independent.

Dependencies

The project currently uses:

Development

Clone the repository and install dependencies:

npm install

For local CLI testing, link the package:

npm link

Then run:

gsize --help

After making changes, you can test the local linked version without publishing a new npm version.

Publishing

To create a new patch version:

npm version patch

Then publish:

npm publish

Future Improvements

Possible future additions:

  • Folder-size analysis
  • Combining multiple options
  • Better error handling
  • Progress indicators for large projects
  • Configurable ignored files/directories
  • More output formats
  • Performance improvements for very large projects

License

ISC

Author

DJ

git-size