Expected to return a value at the end of arrow function when connecting to MongoDB

I am getting the eslint error:

[eslint] Expected to return a value at the end of arrow function. [consistent-return]

I've checked and each path has a return statement. But I feel like my callback function is throwing it for a loop?

Here's the code:

let db;

module.exports.initDb = (callback) => {
if (db) {
return callback(null, db);
}

MongoClient.connect(process.env.MONGO_URL, { useNewUrlParser: true }, (err, client) => {
if (err) {
return callback(err);
}

db = client.db('partsync');
return callback(null, db);

});
};


#node-js #mongodb

1 Likes36.10 GEEK