To convert a directory structure in the filesystem to JSON with Node.js, we use the
To install it, we run
npm i directory-tree
Then we use it by writing
const directoryTree = require("directory-tree"); const tree = directoryTree("/some/path"); const filteredTree = directoryTree("/some/path", [".jpg", ".png"]);
directoryTree to return an object of the directory structure with the /some/path folder as root.
We can also call it with a 2nd argument to filter the items by extension.