我有:
var MongoStore = ConnectMongo(express);
sessionStore = new MongoStore({
db: databaseName,
port: port,
host: host,
})
debugger;
sessionStore.db.on("error", function(err) {
// code never reached and throws the error
// I need to reach this code and don't throw that error.
console.log("Check if your mongodb database is running at " + host + ':' + port + " ".yellow);
return console.log(err.message.red);
});
但它没有发现错误。你知道更好的方法吗?
抛出错误:
C:\web\easy-express\node_modules\connect-mongo\lib\connect-mongo.js:155
throw new Error('Error connecting to database <' + err + '>');
^
Error: Error connecting to database <Error: failed to connect to [localhost:27017]>
at C:\web\easy-express\node_modules\connect-mongo\lib\connect-mongo.js:155:17
at C:\web\easy-express\node_modules\connect-mongo\node_modules\mongodb\lib\mongodb\db.js:229:16
at null.<anonymous> (C:\web\easy-express\node_modules\connect-mongo\node_modules\mongodb\lib\mongodb\connection\server.js:578:7)
at EventEmitter.emit (events.js:106:17)
at null.<anonymous> (C:\web\easy-express\node_modules\connect-mongo\node_modules\mongodb\lib\mongodb\connection\connection_pool.js:139:15)
at EventEmitter.emit (events.js:98:17)
at Socket.<anonymous> (C:\web\easy-express\node_modules\connect-mongo\node_modules\mongodb\lib\mongodb\connection\connection.js:475:10)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:441:14
at process._tickCallback (node.js:415:13)
感谢