Skip to content

Node.js based forum software built for the modern web

#631

Baris Usakli0000a7f0b921
diff --git a/package.json b/package.json
index 84aa875645..8c7cb7eea9 100644
--- a/package.json
+++ b/package.json
@@ -14,14 +14,10 @@
},
"dependencies": {
"socket.io": "~0.9.16",
- "redis": "0.8.3",
- "mongodb": "~1.3.19",
"express": "3.2.0",
"express-namespace": "~0.1.1",
"emailjs": "0.3.4",
"cookie": "0.0.6",
- "connect-redis": "1.4.5",
- "connect-mongo": "0.4.0",
"passport": "0.1.17",
"passport-local": "0.1.6",
"passport-twitter": "0.1.5",
@@ -50,6 +46,10 @@
"semver": "~2.2.1"
},
"optionalDependencies": {
+ "redis": "0.8.3",
+ "mongodb": "~1.3.19",
+ "connect-redis": "1.4.5",
+ "connect-mongo": "0.4.0",
"hiredis": "~0.1.15"
},
"devDependencies": {
diff --git a/src/database/mongo.js b/src/database/mongo.js
index d6af3bc0b2..2a97b77997 100644
--- a/src/database/mongo.js
+++ b/src/database/mongo.js
@@ -2,17 +2,25 @@
(function(module) {
'use strict';
- var mongoClient = require('mongodb').MongoClient,
- winston = require('winston'),
+ var winston = require('winston'),
async = require('async'),
nconf = require('nconf'),
express = require('express'),
- mongoStore = require('connect-mongo')(express),
- mongoHost = nconf.get('mongo:host'),
- db;
+ db,
+ mongoClient,
+ mongoStore;
+
+ try {
+ mongoClient = require('mongodb').MongoClient;
+ mongoStore = require('connect-mongo')(express);
+ } catch (err) {
+ winston.error('Unable to initialize mongo! ' + err.message);
+ process.exit();
+ }
+
module.init = function(callback) {
- mongoClient.connect('mongodb://'+ mongoHost + ':' + nconf.get('mongo:port') + '/' + nconf.get('mongo:database'), function(err, _db) {
+ mongoClient.connect('mongodb://'+ nconf.get('mongo:host') + ':' + nconf.get('mongo:port') + '/' + nconf.get('mongo:database'), function(err, _db) {
if(err) {
winston.error("NodeBB could not connect to your Mongo database. Mongo returned the following error: " + err.message);
process.exit();
diff --git a/src/database/redis.js b/src/database/redis.js
index d24573384b..2cdf43843e 100644
--- a/src/database/redis.js
+++ b/src/database/redis.js
@@ -2,16 +2,24 @@
(function(module) {
'use strict';
- var redisClient,
- redis = require('redis'),
- winston = require('winston'),
+ var winston = require('winston'),
nconf = require('nconf'),
express = require('express'),
- connectRedis = require('connect-redis')(express),
- reds = require('reds'),
-
redis_socket_or_host = nconf.get('redis:host'),
- utils = require('./../../public/src/utils.js');
+ utils = require('./../../public/src/utils.js'),
+ redis,
+ connectRedis,
+ reds,
+ redisClient;
+
+ try {
+ redis = require('redis');
+ connectRedis = require('connect-redis')(express);
+ reds = require('reds');
+ } catch (err) {
+ winston.error('Unable to initialize redis! ' + err.message);
+ process.exit();
+ }
if (redis_socket_or_host && redis_socket_or_host.indexOf('/')>=0) {