Skip to content

Instantly share code, notes, and snippets.

@andrejarrell

andrejarrell/readDir.js

Last active Mar 4, 2021
Embed
What would you like to do?
Recursive Read Directory Module
let fs = require('fs')
let readDir = path => {
let items = fs.readdirSync(path, { withFileTypes: true })
items.forEach(item => {
if (item.isDirectory()) {
readDir(`${path}/${item.name}`)
} else {
routes.push(`${path}/${item.name}`)
}
})
}
module.exports = path => {
routes = []
readDir(path)
return routes
}
@andrejarrell

This comment has been minimized.

Copy link
Owner Author

@andrejarrell andrejarrell commented Mar 4, 2021

Module is available on NPM @andrejarrell/readdir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment