aboutsummaryrefslogtreecommitdiffhomepage
path: root/initializers/database.js
blob: 96c1726373dacb53e128ce9f81ce49298553e756 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
;(function () {
  '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
})()