[Node.js] List entries in a directory

Created on November 30, 2026

Use fs.readdirSync to read the names of the immediate files and subdirectories. This example uses /tmp/dummy_files.

.
├── hello.txt
├── sub
│   └── goodbye.txt
└── world.txt
const fs = require("fs");

let files = fs.readdirSync("/tmp/dummy_files");
files.forEach(file => {
  console.log(file);
});

Example output

hello.txt
sub
world.txt
Node.js