1

I am using node-hound as a directory watcher.

hound = require('hound');

watcher = hound.watch('/dir');

watcher.on('create', function(file) {
  console.log('hello');
});
watcher.on('change', function(file) {
  console.log('hello');
});

How can I bind together the create and the change events assuming that the callback function will perform the exact same task? Is that possible?

R T
  • 1,038
  • 9
  • 17

1 Answers1

0

Just declare only a single function and pass that to both on calls:

const hound = require('hound');

function hello(file) {
  console.log('hello');
}
const watcher = hound.watch('/dir');
watcher.on('create', hello);
watcher.on('change', hello);
Bergi
  • 630,263
  • 148
  • 957
  • 1,375