Nodejs FS module returning no such file or dir err

2020-04-21 07:52发布

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 futher information is required, ask and I will provide.

Thank you all in advance.

1条回答
ゆ 、 Hurt°
2楼-- · 2020-04-21 08:30

try with __dirname:

fs.readdir(__dirname +'/commands/', (err, files) => {
// Do something... 
})
查看更多
登录 后发表回答