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

                                    
 
                                           
 


                          


                                                         
 
                  

                  
 


                                                                   
                                                
    
 



                                              
 
                                                                              
 
                         
'use strict'

const config = require('config')
const mongoose = require('mongoose')

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

// Bootstrap models
require('../models/video')

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

const database = {
  connect: connect
}

function connect () {
  mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname)
  mongoose.connection.on('error', function () {
    throw new Error('Mongodb connection error.')
  })

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

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

module.exports = database