Use fs.stat to check if path is file or dir