How to use the path.exists function in path

To help you get started, we’ve selected a few path 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 hideo55 / node-shipitjs / lib / ShipIt.js View on Github external
return cb(err);
      try {
        pkg = JSON.parse(data);
        if(!pkg || !pkg.version) {
          throw new Error("Bad package.json");
        }
      } catch (e) {
        return cb(e);
      }
      // get version from package.json
      state.setVersion(pkg.version);

      var mainFile = pkg.main;
      if(mainFile) {
        var mainFilePath = path.normalize(path.join(cwd, mainFile));
        path.exists(mainFilePath, function(exists) {
          if(exists) {
            if(mainFilePath.match(/\.js$/)) {
              // Main file must be .js file
              state.setMainFilePath(mainFilePath);
            }
          } else {
            // mainFilePath is directory
            var tmp = path.join(mainFilePath, 'index.js');
            path.exists(tmp, function(exists) {
              if(exists) {
                state.setMainFilePath(tmp);
              }
            });
          }
        });
      } else {
github flackr / lobby / lobby-server / lobby-server.js View on Github external
// If no gameId is specified, return all the games from the lobby 
        // server.
        if (!gameId) {
          games = [];
          for (gameId in gameIdMap)
            for (var i = 0, game; game = gameIdMap[gameId][i++];)
              games.push(game);
        }

        response.end(JSON.stringify({'games': games}));
      } else {
        if (requestPath == '/')
          requestPath = '/' + defaultHtml;
        var filePath = www + requestPath.replace('../', './');
        path.exists(filePath, function(exists) {
          if (!exists) {
            response.writeHead(404);
            response.end();
            return;
          }
          fs.readFile(filePath, function(error, content) {
            if (error) {
              response.writeHead(500);
              response.end();
              return;
            }

            response.writeHead(200, {'Content-Type': getContentType(filePath)});
            response.end(content);
          });
        });
github mcantelon / node-deja / lib / deja_helpers.js View on Github external
exports.createSymlinkIfPathExists = function(symlinkPath, filePath) {

  path.exists(symlinkPath, function(exists) {

    if (!exists) {

      console.log('  ' + symlinkPath + ' -> ' + filePath)
      fs.symlinkSync(filePath, symlinkPath)
    }
    else {

      console.log('  Skipped ' + filePath + ': already exists.')
    }
  })
}
github tsmith / node-control / lib / controller.js View on Github external
function scp(local, remote, callback, exitCallback) {
    if (!local) { 
        throw new Error(this.address + ': No local file path');
    }

    if (!remote) { 
        throw new Error(this.address + ': No remote file path');
    }

    var controller = this,
        user = this.user,
        options = this.scpOptions,
        address = this.address;
    path.exists(local, function (exists) {
        if (exists) {
            var reference = user + '@' + address + ':' + remote,
                args = ['-r', local, reference],
                child;

            if (options) {
                args = options.concat(args);
            }

            controller.log(user + ':scp: ' + local + ' ' + reference);
            child = spawn('scp', args);
            controller.listen(child, callback, exitCallback);
        } else {
            throw new Error('Local: ' + local + ' does not exist');
        }
    });
github TBEDP / tjob / util.js View on Github external
var mkdirs = module.exports.mkdirs = function(dirpath, mode, callback) {
	path.exists(dirpath, function(exists) {
		if(exists) {
			callback(dirpath);
		} else {
			//尝试创建父目录,然后再创建当前目录
			mkdirs(path.dirname(dirpath), mode, function(){
				fs.mkdir(dirpath, mode, callback);
			});
		}
	});
};
github pgte / alfred / lib / alfred / files / temp_file.js View on Github external
var makePath = function(callback) {
  var self = this;
  var randomString = 'alfred_sync_' + createRandomString(64) + '_' + Date.now();
  var file_path= '/tmp/' + randomString;
  path.exists(file_path, function(exists) {
    if (exists) {
      makePath(callback);
    } else {
      callback(file_path);
    }
  });
};
github cloudkick / cast / lib / bundles / index.js View on Github external
BundleManager.prototype.bundleExists = function(name, version, callback) {
  path.exists(this.getBundleFilePath(name, version), callback);
};
github rmx / threejs-collada / simpleServer.js View on Github external
break;
        case '.css':
            contentType = 'text/css';
            break;
        case '.jpg':
            contentType = 'image/jpeg';
            break;
        case '.png':
            contentType = 'image/png';
            break;
        case '.gif':
            contentType = 'image/gif';
            break;
    }
     
    path.exists(filePath, function(exists) {
     
        if (exists) {
            fs.readFile(filePath, function(error, content) {
                if (error) {
                    response.writeHead(500);
                    response.end();
                }
                else {
                    response.writeHead(200, { 'Content-Type': contentType });
                    response.end(content, 'utf-8');
                }
            });
        }
        else {
            response.writeHead(404);
            response.end();
github cloudkick / cast / lib / cast-client / commands / deploy.js View on Github external
function checkIfBundleExistsLocally(callback) {
      var bundlePath = path.join(applicationPath, '.cast-project/tmp',
                                 tarballName);
      path.exists(bundlePath, async.apply(callback, null));
   },