How do you get a list of the names of all files present in a directory in Node.js?

后端 未结 25 1240
天涯浪人
天涯浪人 2020-11-22 07:47

I\'m trying to get a list of the names of all the files present in a directory using Node.js. I want output that is an array of filenames. How can I do this?

25条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 08:27

    I've recently built a tool for this that does just this... It fetches a directory asynchronously and returns a list of items. You can either get directories, files or both, with folders being first. You can also paginate the data in case where you don't want to fetch the entire folder.

    https://www.npmjs.com/package/fs-browser

    This is the link, hope it helps someone!

提交回复
热议问题