# dir2tree

> a user-friendly Node.js tool for creating organized directory trees from a root directory. It offers customization options for tailored tree generation and content analysis

Latest version **0.3.3** (published 2026-03-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install dir2tree
pnpm add dir2tree
yarn add dir2tree
bun add dir2tree
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.3.3 |
| Published | 2026-03-01 |
| First published | 2023-10-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 2 |
| Unpacked size | 35.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 39 |
| Author | zakaria elalaoui |
| Maintainers | zakarialaoui10 |
| Keywords | directory, tree, structure, filesystem, file management, directory tree, json |

## Links

- npm: https://www.npmjs.com/package/dir2tree
- Repository: https://github.com/zakarialaoui10/dir2tree
- Issues: https://github.com/zakarialaoui10/dir2tree/issues
- npm.io page: https://npm.io/package/dir2tree

## Dependencies (2)

- [ziko](https://npm.io/package/ziko.md) ^0.68.2
- [mapfun](https://npm.io/package/mapfun.md) ^0.9.17

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.3.3 (latest) — 2026-03-01
- 0.3.2 — 2023-10-28
- 0.2.2 — 2023-10-26
- 0.2.1 — 2023-10-26
- 0.2.0 — 2023-10-25
- 0.1.2 — 2023-10-24
- 0.1.1 — 2023-10-23
- 0.1.0 — 2023-10-23

## README

## Demo           

[Want to try !](https://replit.com/@zakariaelalaoui/dir2tree#generated.json) 
## Install ![npm](https://img.shields.io/npm/v/dir2tree)
```bash 
npm install dir2tree
```
## Import
### Common Js
```js
const dir2tree=require("dir2tree")
```
### Es Module
```js
import dir2tree from dir2tree
```
## Syntaxe
### Initialise
```js
const MyTree=dir2tree(ROOT,OPTIONS,CALLBACKS)
MyTree.write(Target,"generated_file.json")
```
#### Arguments
- **`ROOT`** : The path to the root directory that we want handle. it's ***`required`***
- **`OPTIONS`** : An object containing various configuration options to control the behavior of the tree generation.it's ***`optional`*** , These options might include :
  - **`fileContent`** : (***Boolean***)
  - **`fileName`** : (***Boolean***)
  - **`fileExtension`** : (***Boolean***)
  - **`length`** : (***Boolean***)
  - **`size`** : (***Boolean***)
  - **`linesCount`** : (***Boolean***)
  - **`created`** : (***Boolean***)
  - **`lastModified`** : (***Boolean***)
  - **`skip`** :
    - **`folder`** : (***String[]***)
    - **`file`** : (***String[]***)
    - **`extension`** : (***String[]***)
  - **`sortBy`** : (***String***) , possible values : `"names"`,`"extension"`,`"size"`,`"lines"`,`"created"`,`"lastmodified"`,
  - **`order`** : (***Number***)
- **`CALLBACKS`** : it's ***`optional`***
### Methodes
- **`.write(Target, filename)`**
- **`.flat(depth, separator)`**
### Use It in your Github Repository
Create a workflow file like the one below.
.github/workflow/dir2tree.yml
```yml
name: Generate Directory Tree using zakarialaoui10/dir2tree
on:
  push: 
    branches:
      - main
jobs:
  build:
    permissions :
      contents : write
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
        with:
          ref: ${{ github.head_ref }}
      - name: Generate Directory Tree
        uses: zakarialaoui10/dir2tree@main
      - name: Commit & Push
        run: |
          git config user.name github-actions
          git config user.email github-actions@github.com
          git add -A .
          git commit -m "generated by zakarialaoui10/dir2tree"
          git push
        env:
          CUSTOM_TOKEN: ${{ secrets.CUSTOM_TOKEN }}
```
## License 
This projet is licensed under the terms of MIT License .<br>
<img src="https://img.shields.io/github/license/zakarialaoui10/zikojs?color=rgb%2820%2C21%2C169%29">

<!-- jsdoc -->

---
_Source: https://npm.io/package/dir2tree · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
