Skip to content

Instantly share code, notes, and snippets.

@sdejean28
Created April 13, 2020 10:45
Show Gist options
  • Save sdejean28/95035b4652bb46c20b04d9d7fe2490bf to your computer and use it in GitHub Desktop.
Save sdejean28/95035b4652bb46c20b04d9d7fe2490bf to your computer and use it in GitHub Desktop.
const mongoose = require('mongoose')
var notifier = require('./notifier.js')
mongoose.connection.on('connected', () => {
 notifier.emit('mongodb_connected');
});
mongoose.connection.on('error', () => {
 setTimeout(function () {
 notifier.emit('mongodb_connect');
 }, 1000)
});
notifier.on('mongodb_connect', () => {
mongoose.connect('mongodb://mongodb/db', {
 useNewUrlParser: true,
 useCreateIndex: true,
 useFindAndModify: true,
 useUnifiedTopology : true
})
});
// startup - first try
notifier.emit('mongodb_connect');
module.exports = {
 mongoose
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment