folder-tree-md
v1.0.1
Published
Fast, zero-dependency CLI & TypeScript library to generate clean Markdown directory trees for READMEs and documentation.
Maintainers
Readme
📁 folder-tree-md
Fast, zero-dependency CLI & TypeScript library to generate clean Markdown directory trees for READMEs, documentation, and technical architecture docs.
✨ Features
- ⚡ Zero Dependencies — Ultra-fast, lightweight, pure native Node.js and TypeScript.
- 💻 CLI & Programmatic API — Run directly via
npx folder-tree-mdor import in your build scripts. - 🛡️ Auto-Ignores Bloat — Automatically skips
node_modules,.git,dist,.next,build, and parses.gitignore. - 🎚️ Depth Control — Limit recursion depth easily with
-d <depth>. - 📁 Directories Only Mode — Focus exclusively on folder architecture.
- 📊 File Size Display — Optional human-readable file sizes (
[1.2 KB]). - 📝 Markdown Ready — Generates formatted
```text ... ```code blocks ready to paste into README.md. - 💾 Save to File — Directly export trees into
.mdor text files with-o <path>.
📥 Installation
As a CLI Tool (Recommended)
You can run it instantly without installation:
npx folder-tree-mdOr install globally:
npm install -g folder-tree-mdAs a Project Dependency (Library)
npm install folder-tree-md🚀 CLI Usage
Basic Usage
Generate tree for the current directory:
npx folder-tree-mdOutput Example
my-project/
├── src/
│ ├── components/
│ │ ├── Button.tsx
│ │ └── Card.tsx
│ ├── utils/
│ │ └── helper.ts
│ └── index.ts
├── tests/
│ └── index.test.ts
├── package.json
├── tsconfig.json
└── README.mdUseful CLI Examples
Limit Traversal Depth:
npx folder-tree-md . -d 2Directories Only:
npx folder-tree-md . --dirs-onlyInclude File Sizes:
npx folder-tree-md ./src -sCustom Ignore Patterns:
npx folder-tree-md . -i "*.log,temp,coverage"Save Output Directly to Markdown File:
npx folder-tree-md . -o PROJECT_STRUCTURE.md💻 Programmatic API Usage
You can also import and use it in your Node.js or TypeScript scripts:
import { generateTree, getTreeData } from 'folder-tree-md';
// 1. Generate formatted markdown tree string
const markdownTree = generateTree('./src', {
maxDepth: 3,
wrapMarkdown: true,
dirsOnly: false,
showSize: true,
});
console.log(markdownTree);
// 2. Or get hierarchical JSON data structure
const treeData = getTreeData('./src');
console.log(JSON.stringify(treeData, null, 2));⚙️ CLI Options Reference
| Flag | Long Flag | Description |
|---|---|---|
| -d | --max-depth <n> | Maximum recursion depth (e.g. 1, 2, 3). |
| -i | --ignore <patterns> | Comma-separated patterns to ignore. |
| | --dirs-only | Only output directories, skip files. |
| | --hidden | Include hidden files and folders (.env, .config, etc.). |
| -s | --size | Include formatted file sizes (e.g., [1.2 KB]). |
| | --raw | Output plain tree without Markdown ```text fence. |
| | --json | Output full JSON data tree structure. |
| -o | --output <file> | Write tree directly to a file. |
| -v | --version | Display current version. |
| -h | --help | Display help and usage information. |
🛠 Development & Testing
# Install dependencies
npm install
# Run unit tests
npm test
# Build dual ESM/CJS bundles + CLI executable + .d.ts types
npm run build💖 Support the Project
If you find this package useful, consider sponsoring its ongoing development and maintenance: 👉 Sponsor @Piratha97 on GitHub Sponsors
📄 License
MIT © 2026 Pirapaakaran Pirathapan
