gabesoft / watch-fs Goto Github PK
View Code? Open in Web Editor NEWFile system watcher
License: Other
File system watcher
License: Other
Hi,
Thanks you for your module, it's really usefull :-)
But currently, I have an error and the nodejs server break if the file doesn't exists on startup :
% node test.js
Could not access path "/www/test/test.txt" { [Error: ENOENT, stat '/www/test/test.txt']
errno: 34,
code: 'ENOENT',
path: '/www/test/test.txt' }
watcher started
The code is your example :
var Watcher = require('watch-fs').Watcher;
var watcher = new Watcher({
paths: [ 'test.txt' ]
});
watcher.on('create', function(name) {
console.log('file ' + name + ' created');
});
watcher.on('change', function(name) {
console.log('file ' + name + ' changed');
});
watcher.on('delete', function(name) {
console.log('file ' + name + ' deleted');
});
watcher.start(function(err) {
console.log('watcher started');
});
There is a solution to ignore it at startup please ?
Regards,
Scenario (yes, this is copy/paste-able into a console):
# preparation
mkdir scenario
cd scenario
npm install watch-fs
# setup
touch file.js
mkdir dir
cd dir
ln -s ../file.js .
cd ..
# now we’re back to the “scenario” root directory
then I put this in quickstart.js
:
var Watcher = require('watch-fs').Watcher;
var watcher = new Watcher({
paths: [ 'dir' ],
filters: {
includeFile: function(name) {
return /\.js/.test(name);
}
}
});
watcher.start(function(err) {
console.log('watcher started');
});
and run it:
~/tmp/scenario ⌘ node quickstart.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 initWatcher (/Users/vlad/tmp/scenario/node_modules/watch-fs/lib/watcher.js:99:32)
at /Users/vlad/tmp/scenario/node_modules/watch-fs/lib/watcher.js:92:9
at Array.forEach (native)
at initWatchers (/Users/vlad/tmp/scenario/node_modules/watch-fs/lib/watcher.js:91:22)
at /Users/vlad/tmp/scenario/node_modules/watch-fs/lib/watcher.js:238:13
at /Users/vlad/tmp/scenario/node_modules/watch-fs/lib/watcher.js:72:9
at /Users/vlad/tmp/scenario/node_modules/watch-fs/node_modules/async/lib/async.js:116:25
~/tmp/scenario ⌘
Now, if I insert a console.log(realPath, fullPath);
at node_modules/watch-fs/lib/watcher.js:99
and run that again, then it shows me this this:
/Users/vlad/tmp/scenario/dir /Users/vlad/tmp/scenario/dir
../file.js /Users/vlad/tmp/scenario/dir/file.js
which basically explains why that line fails:
map[fullPath].watcher = fs.watch(realPath, function (event, name) {
that is, it’s trying to fs.watch()
../file.js
which is not exactly there… ;) I didn’t look too deep into this, but I think that using fs.realpathSync()
instead of fs.readlinkSync()
in the buildMap
function would fix that, but I’m afraid that there might be more to the picture, and this is why I’m not creating a pull request. :->
So, what do you think? :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.