console.log(fs.statSync('./_test/'));如果_test不存在,会报错。并没有返回值,那么如何判断文件夹是否存在呢?
忘记说了我是node6, fs.exists这个文档已经明确指出 废弃了
拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...
fs.exists is deprecated, it is recommended to use fs.stat and fs.access. The following is what I use in my project:
//检测文件或者文件夹存在 nodeJS function fsExistsSync(path) { try{ fs.accessSync(path,fs.F_OK); }catch(e){ return false; } return true; }
Of course, this is only the synchronous version. If you need an asynchronous version, you can modify it yourself~ If it is useful, please update it below your question so that future generations can view it.
https://nodejs.org/dist/lates...Here are detailed instructions, take a look
Use where node
I remember that there is fs.exists and fs.existsSync, both of which can determine whether it exists. The latter one is synchronous
fs.exists is deprecated, it is recommended to use fs.stat and fs.access. The following is what I use in my project:
Of course, this is only the synchronous version. If you need an asynchronous version, you can modify it yourself~ If it is useful, please update it below your question so that future generations can view it.
https://nodejs.org/dist/lates...
Here are detailed instructions, take a look
Use where node
I remember that there is fs.exists and fs.existsSync, both of which can determine whether it exists. The latter one is synchronous