aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/database.js
blob: 830cc7dd8e455287e51f5af0be7cd0000745380c (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
'use strict'

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

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

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