0

I can't get the serial example from here but I can't provide the link(?):

NodeJS: How would one watch a large amount of files/folders on the server side for updates?

var fs = require('fs');
var walk = function(dir, done) {
  var results = [];
  fs.readdir(dir, function(err, list) {
    if (err) return done(err);
    var i = 0;
    (function next() {
      var file = list[i++];
      if (!file) return done(null, results);
      file = dir + '/' + file;
      fs.stat(file, function(err, stat) {
        if (stat && stat.isDirectory()) {
          walk(file, function(err, res) {
            results = results.concat(res);
            next();
          });
        } else {
          results.push(file);
          next();
        }
      });
    })();
  });
};

I have tried this to call the function but I am not sure what parameters it needs. Can someone please advise?

//walk(process.env.HOME, function(err, results) {
walk("C:\", function(err, results) {
  if (err) throw err;
  console.log(results);
});

the error I'm getting is

module.js:437
  var compiledWrapper = runInThisContext(wrapper, filename, true);
                        ^
SyntaxError: Unexpected token ILLEGAL
    at Module._compile (module.js:437:25)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:492:10)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)

1 Answer 1

1

Escape your \. Use "C:\\" not "C:\".

Sign up to request clarification or add additional context in comments.

2 Comments

tks Dan, no errors now but it just sits there and does not do 'console.log();'. It's curently just waiting on something at the min.
Doh!! that works it's just a rather long wait giving a big file. tks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.