I understand that we should not return objects in node.js asynchronous functions and that every path inside the asynchronous function should lead to the callback function. To solve the "pyramid of doom" problem to some extent and for better readability, is it ok to just say "return;" after calling the callback function so I don't have to put the rest of the code in the else block and skip indenting and get better readability. The code has been working fine so far but just wondering if there are any potential issues I'm overlooking.
(function(database) {
var mongodb = require("mongodb");
database.ObjectID = mongodb.ObjectID;
var mongoUrl = "mongodb://localhost:27017/mydb";
var dbconn = null;
database.getDBConn = function(next){
if(dbconn){ next(null, dbconn); return; } //already connected: return dbconn
mongodb.MongoClient.connect(mongoUrl,function(err, database){
if(err){ next(err, null); return; } //connection fail: return error
dbconn = {db: database,
movies: database.collection("movie") };
next(null, dbconn); //connection success: return dbconn
});
}
})(module.exports);