How does npm draw the dependency tree? How does npm draw the dependency tree? node.js node.js

How does npm draw the dependency tree?


npm uses the Unicode box drawing characters (U+2500-2800) to draw the pretty lines of the tree.

To draw a similar tree in your own application, the best route is probably to use the same module that npm itself uses – archy.

var archy = require('archy');var s = archy({  label : 'beep',  nodes : [    'ity',    {      label : 'boop',      nodes : [        {          label : 'o_O',          nodes : [            {              label : 'oh',              nodes : [ 'hello', 'puny' ]            },            'human'          ]        },        'party\ntime!'      ]    }  ]});console.log(s);

Outputs

beep├── ity└─┬ boop  ├─┬ o_O  │ ├─┬ oh  │ │ ├── hello  │ │ └── puny  │ └── human  └── party      time!


For list your folders and files you can use tree-cli:

https://www.npmjs.com/package/tree-cli

Just install:

npm install -g tree-cli

And use inside your folder:

tree -L 2, -d


You could also use console2 which does almost the same thing as archy does, but gives you useful additional features like improved stack traces, object inspection and more:

enter image description here

Feature screenshot

Full disclosure: I'm the author of the repository