This question evaluates proficiency with filesystem I/O, path validation, directory traversal, recursion and error handling in Node.js, plus the ability to produce deterministic directory listings in either an indented tree or structured JSON representation.
You are given an absolute or relative file-system path rootPath.
Write a Node.js function/program that:
rootPath
exists.
rootPath
.
Choose one of the following and document it clearly in your answer:
root/
a.txt
sub/
b.js
{ name, type, children }
.
rootPath
is a file, output just that file.
rootPath
is a directory, include all immediate children (optionally recursively—state which you implement).