Categories
JavaScript Answers

How to get a list of filenames in folder with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *