Sometimes, we want to get a list of filenames in folder with JavaScript.
In this article, we’ll look at how to get a list of filenames in folder with JavaScript.
How to get a list of filenames in folder with JavaScript?
To get a list of filenames in folder with JavaScript, we use the Node.js fs.readdirSync
method.
For instance, we write
const fs = require("fs");
const files = fs.readdirSync("/assets/photos/");
to call readdirSync
with the folder path that we want to get the filenames from.
Conclusion
To get a list of filenames in folder with JavaScript, we use the Node.js fs.readdirSync
method.