function directorySize(path, cb, size) {
  if (size === undefined) {
    size = 0;
  }

  fs.stat(path, function (err, stat) {
    if (err) {
      cb(err);
      return;
    }

    size += stat.size;

    if (!stat.isDirectory()) {
      cb(null, size);
      return;
    }

    fs.readdir(path, function (err, paths) {
      if (err) {
        cb(err);
        return;
      }

      async.map(
        paths.map(function (p) {
          return path + "/" + p;
        }),
        directorySize,
        function (err, sizes) {
          size += sizes.reduce(function (a, b) {
            return a + b;
          }, 0);
          cb(err, size);
        },
      );
    });
  });
}
You can use a nodejs module to do this, this function is really straightforward and will fail on error
Note that when computing a directory size you may want to skip some errors (like ENOENT)
That said, this is for demonstration purpose and may not suit a production environnment