Nodejs FS module returning no such file or dir error

久未见 提交于 2019-12-11 11:23:25

问题


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:


try with __dirname:

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


来源:https://stackoverflow.com/questions/50966704/nodejs-fs-module-returning-no-such-file-or-dir-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!