Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
list files in a directory with node.js
var fs = require('fs'),
path = require('path')
var listFiles = function(dir, next){
fs.readdir(dir, function(err, nodes){
if (err) next(err)
next(null, nodes.filter(function(node){
return fs.lstatSync(path.resolve(dir) + "/" + node).isFile()
}))
})
}
// usage: listFiles(dirName)
// example:
// listFiles('./public/images/', function(err, files){
// if (err) throw err
// console.log(files)
// })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.