I think you can replace this function with shelljs.which()