How to use the filer.fs.stat function in filer

To help you get started, we’ve selected a few filer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github humphd / nohost / src / webserver.js View on Github external
function maybeServeIndexFile() {
        const indexPath = Path.join(path, directoryIndex);

        fs.stat(indexPath, function(err, stats) {
          if(err) {
            if(err.code === 'ENOENT' && !disableIndexes) {
              // Fallback to a directory listing instead
              serveDirListing();
            } else {
              // Let the error (likely 404) pass through instead
              serveError(path, err);
            }
          } else {
            // Index file found, serve that instead
            serveFile(indexPath, stats);
          }
        });
      }
github humphd / nohost / src / webserver.js View on Github external
function serveDirListing() {
        sh.ls(path, function(err, entries) {
          if(err) {
            return serveError(path, err);
          }
  
          const responseData = formatter.formatDir(route, path, entries);
          resolve(new Response(responseData.body, responseData.config));
        });
      }

      maybeServeIndexFile();
    }

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

      if(stats.isDirectory()) {
        serveDir(path);
      } else {
        serveFile(path, stats);
      }
    });
  });
};