Reconfigura models/connection.js

This commit is contained in:
Michel Pereira 2021-10-23 14:08:47 -03:00
parent 5d9bc08322
commit 14ae4d44fe
5 changed files with 13 additions and 15 deletions

2
.gitignore vendored
View file

@ -120,7 +120,7 @@ fabric.properties
.LSOverride
# Icon must end with two \r
Icon
Icon
# Thumbnails
._*

2
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,2 @@
{
}

View file

@ -1,29 +1,25 @@
const { MongoClient } = require('mongodb');
require('dotenv').config();
const OPTIONS = {
useNewUrlParser: true,
useUnifiedTopology: true,
};
// Para usar com o avaliador:
// const MONGO_DB_URL = 'mongodb://mongodb:27017/StoreManager';
// Para uso local:
const MONGO_DB_URL = 'mongodb://localhost:27017/StoreManager';
// const DB_NAME = 'StoreManager'; // outra maneira
const MONGO_DB_URL = process.env.DB_URL || 'mongodb://mongodb:27017/StoreManager';
let db = null;
const connection = () => (db
? Promise.resolve(db)
: MongoClient.connect(MONGO_DB_URL, OPTIONS)
.then((conn) => {
// db = conn.db(DB_NAME); // outra maneira
db = conn.db();
return db;
})
.catch((err) => {
console.log(err);
process.exit(1);
}));
module.exports = connection;

2
package-lock.json generated
View file

@ -12,7 +12,7 @@
"@hapi/boom": "^9.1.0",
"@hapi/joi": "^17.1.1",
"body-parser": "^1.19.0",
"dotenv": "^8.2.0",
"dotenv": "^8.6.0",
"express": "^4.17.1",
"express-rescue": "^1.1.26",
"faker": "^4.1.0",

View file

@ -23,7 +23,7 @@
"@hapi/boom": "^9.1.0",
"@hapi/joi": "^17.1.1",
"body-parser": "^1.19.0",
"dotenv": "^8.2.0",
"dotenv": "^8.6.0",
"express": "^4.17.1",
"express-rescue": "^1.1.26",
"faker": "^4.1.0",