nodejs fs.exists() [英] nodejs fs.exists()
问题描述
我正在尝试在节点脚本中调用 fs.exists
但我收到错误:
I'm trying to call fs.exists
in a node script but I get the error:
TypeError:对象#没有方法'存在'
TypeError: Object # has no method 'exists'
我试过替换 fs.exists()
with require('fs')。exists
,甚至 require('path')。存在
(以防万一),但这些都没有用我的IDE列出方法 exists()
。 fs
在我的脚本顶部声明为 fs = require('fs');
我已经使用过了它以前读过文件。
I've tried replacing fs.exists()
with require('fs').exists
and even require('path').exists
(just in case), but neither of these even list the method exists()
with my IDE. fs
is declared at the top of my script as fs = require('fs');
and I've used it previously to read files.
如何调用 exists()
?
推荐答案
您的要求声明可能不正确,请确保您拥有以下
Your require statement may be incorrect, make sure you have the following
var fs = require("fs");
fs.exists("/path/to/file",function(exists){
// handle result
});
阅读此处的文档
http://nodejs.org/api/fs.html#fs_fs_exists_path_callback
这篇关于nodejs fs.exists()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!