Skip to content

Instantly share code, notes, and snippets.

@bestickley
Created March 29, 2022 20:21
Show Gist options
  • Save bestickley/e3305f315db54ad874b9b2f1a466116f to your computer and use it in GitHub Desktop.
Save bestickley/e3305f315db54ad874b9b2f1a466116f to your computer and use it in GitHub Desktop.
Node.js Recursively Get URLs
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