我正在尝试在 Node 脚本中调用 fs.exists
但出现错误:
TypeError: Object # has no method 'exists'
我尝试将 fs.exists()
替换为 require('fs').exists
甚至 require('path').exists
(以防万一),但这些都没有在我的 IDE 中列出方法 exists()
。 fs
在我的脚本顶部声明为 fs = require('fs');
并且我以前用它来读取文件。
如何调用exists()
?
最佳答案
您的require语句可能不正确,请确保您有以下内容
var fs = require("fs");
fs.exists("/path/to/file",function(exists){
// handle result
});
在此处阅读文档
关于javascript - nodejs fs.exists(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13589070/