Issues (34)

app/database/index.js (1 issue)

1
'use strict';
2
3
var config 		= require('../config');
4
var Mongoose 	= require('mongoose');
5
var logger 		= require('../logger');
6
7
// Connect to the database
8
// construct the database URI and encode username and password.
9
var dbURI = "mongodb://" + 
10
			encodeURIComponent(config.db.username) + ":" + 
11
			encodeURIComponent(config.db.password) + "@" + 
12
			config.db.host + ":" + 
13
			config.db.port + "/" + 
14
			config.db.name;
15
Mongoose.connect(dbURI);
16
17
// Throw an error if the connection fails
18
Mongoose.connection.on('error', function(err) {
19
	if(err) throw err;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
20
});
21
22
// mpromise (mongoose's default promise library) is deprecated, 
23
// Plug-in your own promise library instead.
24
// Use native promises
25
Mongoose.Promise = global.Promise;
26
27
module.exports = { Mongoose, 
28
	models: {
29
		user: require('./schemas/user.js'),
30
		room: require('./schemas/room.js')
31
	}
32
};