Created
September 2, 2015 13:34
-
-
Save hai5nguy/51a9d48564cdc917fc89 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gulp.task('mongo-start', function (cb) { | |
var tries = 0; | |
startMongo(); | |
var timer = setInterval(connectToMongo, 2000); | |
function startMongo() { | |
exec('mongod --dbpath ./localdb/db/'); | |
} | |
function connectToMongo() { | |
if (tries >= 3) { | |
clearTimeout(timer); | |
cb('Unable to start local mongo server'); | |
return; | |
} | |
MongoClient.connect('mongodb://localhost:27017/sanspantalones', function (error, database) { | |
if (error) { | |
startMongo(); | |
} else { | |
clearTimeout(timer); | |
cb(); | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment