2014-05-15 5 views
1

그래, node.js가 나를 미치게 만들었습니다. 나는이 책에서 똑같은 코드를 실행하려고 노력해왔다. 그러나 그것은 나에게 오류를 던지고있다. 코드는 간단하고 변경을 위해 파일을 감시합니다.Node.js FS 모듈 시작 문제

const fs= require('fs'); 

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

코드 용 js 파일과 text.txt는 같은 dir에 있습니다. 이 오류가 발생합니다.

$ 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) 

미리 감사드립니다. 노드 학습을위한 uptodate 소스도 적합합니다. 2 권의 책을 읽었으며 예제 코드도 실행할 수 없습니다.

+1

'ENOENT'은 파일을 찾을 수 없음을 의미합니다. 그냥 궁금해서'fs.stat ('target.txt', console.log)'할 수 있습니까? 'fs.watch' 또는 구현과 관련하여 문제가 있는지 봅시다. – zamnuts

+0

그것이 지금 변화를 target.txt를보고 초 후 인쇄 오류에 근무 {[오류 : ENOENT, STAT 'C : \ cygwin64 집 \ \ 신안 \ 시도의 \의 target.txt'] 의 errno : 34 코드 : 'ENOENT', 경로 : 'C : \\ cygwin64 \\ home \\ Sinan \\ try \\ target.txt'} – sinanspd

+0

@sinanspd 늦었지만 비슷한 문제가있었습니다. 작성한 파일과보고있는 파일이 같은 이름인지 확인하십시오. 내 경우에는 오타가 더 많았습니다. – Mandeep

답변

0

.txt 확장자가 제거되어 작동했습니다.

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