aboutsummaryrefslogblamecommitdiffhomepage
path: root/initializers/database.js
blob: 6e3f11df3969474f942bdd23a6408884434f3b58 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
            
 

                                  
 
                                         
 


                                                       
 


                  
 





                                                                   
 



                                              
 
                                                                              
 
                         
'use strict'

var config = require('config')
var mongoose = require('mongoose')

var logger = require('../helpers/logger')

var dbname = 'peertube' + config.get('database.suffix')
var host = config.get('database.host')
var port = config.get('database.port')

var database = {
  connect: connect
}

function connect () {
  mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname)
  mongoose.connection.on('error', function () {
    logger.error('Mongodb connection error.')
    process.exit(0)
  })

  mongoose.connection.on('open', function () {
    logger.info('Connected to mongodb.')
  })
}

// ---------------------------------------------------------------------------

module.exports = database