這篇文章主要介紹了node.js中的fs.existsSync方法使用說明,本文介紹了fs.existsSync方法說明、語法、接收參數、使用實例和實現源碼,需要的朋友可以參考下
方法說明:
同步版的 fs.exists() 。
語法:
復制代碼代碼如下:
fs.existsSync(path)
由于該方法屬于fs模塊,使用前需要引入fs模塊(var fs= require(“fs”) )
接收參數:
path 欲檢測的文件路徑。
源碼:
復制代碼代碼如下:
fs.existsSync = function(path) {
try {
nullCheck(path);
binding.stat(pathModule._makeLong(path));
return true;
} catch (e) {
return false;
}
};