mirror of https://github.com/Chocobozzz/PeerTube
30 lines
693 B
JavaScript
30 lines
693 B
JavaScript
'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 () {
|
|
throw new Error('Mongodb connection error.')
|
|
})
|
|
|
|
mongoose.connection.on('open', function () {
|
|
logger.info('Connected to mongodb.')
|
|
})
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
module.exports = database
|