user8500190
user8500190

Reputation:

Nodejs FS module returning no such file or dir error

Code:

fs.readdir('./commands/', (err, files) => {
     // Do something... 
});

Error:

ENOENT: no such file or directory, scandir './commands/'

The folder ./commands/ does exist. This file is src/index.js and is trying to read the directory of src/commands/. It wouldn't be fs.readdir('/commands' because that would be referring to the root directory of my PC (Ubuntu 18.04 LTS, Node version v8.10.0). If any further information is required, ask and I will provide it.

Thank you all in advance.

Upvotes: 4

Views: 2865

Answers (1)

crellee
crellee

Reputation: 915

try with __dirname:

fs.readdir(__dirname +'/commands/', (err, files) => {
// Do something... 
})

Upvotes: 5

Related Questions