Created
March 29, 2022 20:21
-
-
Save bestickley/e3305f315db54ad874b9b2f1a466116f to your computer and use it in GitHub Desktop.
Node.js Recursively Get URLs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function getUrlsSync(rootUrl: URL): URL[] { | |
const dirents = readdirSync(rootUrl, { withFileTypes: true }); | |
const urls = dirents.map((dirent) => { | |
const url = new URL(rootUrl + "/" + dirent.name); | |
return dirent.isDirectory() ? getUrlsSync(url) : url; | |
}); | |
return urls.flat(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment