How can i get client.db(db_name) from export module to main.js using async/await or promise ...
main.js
var express = require('express')
var app = express();
enter code here
// Web server port number.
const port = 4343;
require('./config/app_config')(app);
db = require('./config/data_config')(app);
db.collection('users');
app.listen(port, () => {
console.log(`Server start at port number: ${port}`);
});
config.js
module.exports = (app) => {
const mongo_client = require('mongodb').MongoClient;
const assert = require('assert');
const url = 'mongodb://localhost:27017';
const db_name = 'portfolio';
mongo_client.connect(url, (err, client) => {
assert.equal(null, err);
console.log('Connection Successfully to Mongo');
return client.db(db_name);
});
};
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…