Skip to content

Instantly share code, notes, and snippets.

@hai5nguy
Created September 2, 2015 13:34
Show Gist options
  • Save hai5nguy/51a9d48564cdc917fc89 to your computer and use it in GitHub Desktop.
Save hai5nguy/51a9d48564cdc917fc89 to your computer and use it in GitHub Desktop.
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