V
V
Vladislav2016-08-20 22:20:52
Node.js
Vladislav, 2016-08-20 22:20:52

Why does the watch method in node.js fire more than once?

There is an index.js file:

const fs = require("fs");

var mainFile = './src/vuefy/main.js';

fs.watch(mainFile, (eventType, filename) => {
  console.log(filename);
  //build();
});

I run node index.js and when main.js changes, the watch method fires twice. Why can this happen?
I'm running under windows 8.1, node v5.12.0.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladislav, 2016-08-20
@MrBikus

This is a windows API issue https://github.com/nodejs/node/issues/3042
You can use fs.watchFile instead of fs.watch, but it is very slow and as it is written in the off-doc: "Note: fs.watch() is more efficient than fs.watchFile and fs.unwatchFile. fs.watch should be used instead of fs.watchFile and fs.unwatchFile when possible."

#
#algooptimize #bottize, 2016-08-20
@user004

Because life is pain.
Why do you think the method should be called once and make a full log output, including the event type.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question