aboutsummaryrefslogtreecommitdiffhomepage
path: root/initializers/database.js
diff options
context:
space:
mode:
Diffstat (limited to 'initializers/database.js')
-rw-r--r--initializers/database.js46
1 files changed, 22 insertions, 24 deletions
diff --git a/initializers/database.js b/initializers/database.js
index 96c172637..6e3f11df3 100644
--- a/initializers/database.js
+++ b/initializers/database.js
@@ -1,32 +1,30 @@
1;(function () { 1'use strict'
2 'use strict'
3 2
4 var config = require('config') 3var config = require('config')
5 var mongoose = require('mongoose') 4var mongoose = require('mongoose')
6 5
7 var logger = require('../helpers/logger') 6var logger = require('../helpers/logger')
8 7
9 var dbname = 'peertube' + config.get('database.suffix') 8var dbname = 'peertube' + config.get('database.suffix')
10 var host = config.get('database.host') 9var host = config.get('database.host')
11 var port = config.get('database.port') 10var port = config.get('database.port')
12 11
13 var database = { 12var database = {
14 connect: connect 13 connect: connect
15 } 14}
16 15
17 function connect () { 16function connect () {
18 mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname) 17 mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname)
19 mongoose.connection.on('error', function () { 18 mongoose.connection.on('error', function () {
20 logger.error('Mongodb connection error.') 19 logger.error('Mongodb connection error.')
21 process.exit(0) 20 process.exit(0)
22 }) 21 })
23 22
24 mongoose.connection.on('open', function () { 23 mongoose.connection.on('open', function () {
25 logger.info('Connected to mongodb.') 24 logger.info('Connected to mongodb.')
26 }) 25 })
27 } 26}
28 27
29 // --------------------------------------------------------------------------- 28// ---------------------------------------------------------------------------
30 29
31 module.exports = database 30module.exports = database
32})()