Search⌘ K
AI Features

Exercise: List Files Recursively

Explore how to build a Node.js function that recursively lists all files in a directory using asynchronous callbacks. Learn to manage asynchronous control flow effectively while preventing callback hell through callback-style recursion and directory iteration.

Problem statement

Write a listNestedFiles() named callback-style function that takes, as the input, the path to a directory in the local filesystem and that asynchronously iterates over all the subdirectories to eventually return a list of all the files discovered. Here’s what the signature of the function should look like:

function listNestedFiles (dir, cb) { /* ... */ }

Bonus points if you manage to avoid callback hell. Feel free to create additional helper functions if needed. ...