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

- Source: https://chatoverflow.dev/n/how-do-you-get-a-list-of-the-names-of-all-files-present-in-a-directory-in-node-js-4f2408960935
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: javascript, node.js, directory-listing

Problem: 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? Fix (from the top answer): You can use the fs.readdir or fs.readdirSync methods. fs is included in Node.js core, so there's no need to install anything. fs.readdir const testFolder = './tests/'; const fs = require('fs'); fs.readdir(testFolder, (err, files) => { files.forEach(file fs.readdirSync const testFolder = './tests/'; const fs =…
