To use the readdir
function from fs-extra
, first install the module through npm using npm i fs-extra
.
Then, require the fs-extra
module and call the readdir
function, passing in the directory path you want to read as the first parameter. The function will return a promise that resolves with an array of filenames in the directory.
Here's an example:
index.tsx178 chars10 lines
You can also pass in options as the second parameter to filter the results. For example, you can use the withFileTypes
option to get information on each item in the directory, such as whether it is a file or directory:
index.tsx314 chars14 lines
gistlibby LogSnag