簡體   English   中英

Node.js FS模塊啟動概率

[英]Node.js FS module start prob

好的,所以node.js一直讓我發瘋。 我一直在嘗試運行與本書完全相同的代碼。 但這使我出錯。 代碼很簡單,可以監視文件中的更改

   const fs= require('fs');

fs.watch('target.txt', function() {
console.log("File 'target.txt' just changed!");
 });
 console.log("Now watching target.txt for changes");

代碼和text.txt的js文件在同一目錄中。 我得到這個錯誤

$ node --harmony watcher.js

 fs.js:1051
throw errnoException(process._errno, 'watch');
      ^
Error: watch ENOENT
at errnoException (fs.js:1019:11)
at FSWatcher.start (fs.js:1051:11)
at Object.fs.watch (fs.js:1076:11)
at Object.<anonymous> (C:\cygwin64\home\Sinan\try\watcher.js:5:5)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)

預先感謝。 我也將適當的最新資源用於學習節點,我嘗試了兩本書,甚至無法運行示例代碼

我刪除了.txt擴展名,並且可以正常工作。

fs.watch('target', function () {
    console.log("File target.txt just changed");
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM