diff options
Diffstat (limited to 'server/initializers/database.js')
-rw-r--r-- | server/initializers/database.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/server/initializers/database.js b/server/initializers/database.js new file mode 100644 index 000000000..a917442ec --- /dev/null +++ b/server/initializers/database.js | |||
@@ -0,0 +1,29 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | var config = require('config') | ||
4 | var mongoose = require('mongoose') | ||
5 | |||
6 | var logger = require('../helpers/logger') | ||
7 | |||
8 | var dbname = 'peertube' + config.get('database.suffix') | ||
9 | var host = config.get('database.host') | ||
10 | var port = config.get('database.port') | ||
11 | |||
12 | var database = { | ||
13 | connect: connect | ||
14 | } | ||
15 | |||
16 | function connect () { | ||
17 | mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname) | ||
18 | mongoose.connection.on('error', function () { | ||
19 | throw new Error('Mongodb connection error.') | ||
20 | }) | ||
21 | |||
22 | mongoose.connection.on('open', function () { | ||
23 | logger.info('Connected to mongodb.') | ||
24 | }) | ||
25 | } | ||
26 | |||
27 | // --------------------------------------------------------------------------- | ||
28 | |||
29 | module.exports = database | ||