Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

nodejs create tree from directories

const { readdirSync } = require("fs");
const { join } = require("path");

const createTreeFromDirectories = (path) => {
	return readdirSync(path, { withFileTypes: true }).reduce((tree, branch) => {
		if (branch.isDirectory()) tree[branch.name] = createTreeFromDirectories(join(path, branch.name));
		return tree;
	}, {});
};

createTreeFromDirectories(process.cwd());
 
PREVIOUS NEXT
Tagged: #nodejs #create #tree #directories
ADD COMMENT
Topic
Name
3+5 =