Skip to content

Commit

Permalink
Created db.js file to as source of mongoose connection
Browse files Browse the repository at this point in the history
  • Loading branch information
shivensinha4 committed Jun 14, 2019
1 parent 3ee542c commit b684e94
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 116 deletions.
217 changes: 110 additions & 107 deletions .idea/workspace.xml

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions app.js
@@ -1,6 +1,6 @@
const express = require("express"),
routes = require("./apiRoutes"),
mongoose = require("mongoose"),
mongoose = require("./helpers/db"),
path = require("path"),
dotenv = require("dotenv"),
bodyParser = require("body-parser"),
Expand All @@ -10,9 +10,6 @@ dotenv.config({ path: path.resolve(__dirname, ".env") });

const app = express();

mongoose.connect(process.env.STEIN_MONGO_URL, { useNewUrlParser: true });
mongoose.Promise = require("bluebird");

app.use(cors());
app.use(bodyParser.json({ type: () => true }));
app.use(bodyParser.urlencoded({ extended: false }));
Expand Down
2 changes: 0 additions & 2 deletions controllers/updateRequestCount.js
@@ -1,5 +1,3 @@
const mongoose = require("mongoose");

module.exports = (req, res, next) => {
const user = res.locals.user;

Expand Down
9 changes: 9 additions & 0 deletions helpers/db.js
@@ -0,0 +1,9 @@
const Mongoose = require("mongoose").Mongoose;

const dbConnection = new Mongoose();

dbConnection.Promise = require("bluebird");
dbConnection.connect(process.env.STEIN_MONGO_URL, { useNewUrlParser: true });


module.exports = dbConnection;
2 changes: 1 addition & 1 deletion models/admin.js
@@ -1,4 +1,4 @@
const mongoose = require("mongoose"),
const mongoose = require("../helpers/db"),
bcrypt = require("bcrypt");

const schema = mongoose.Schema({
Expand Down
2 changes: 1 addition & 1 deletion models/storage.js
@@ -1,4 +1,4 @@
const mongoose = require("mongoose");
const mongoose = require("../helpers/db");

const schema = mongoose.Schema({
googleId: {
Expand Down
2 changes: 1 addition & 1 deletion models/user.js
@@ -1,4 +1,4 @@
const mongoose = require("mongoose"),
const mongoose = require("../helpers/db"),
googleAuthLib = require("google-auth-library"),
googleOAuthConfig = require("../helpers/authentication/configuration").google;

Expand Down

0 comments on commit b684e94

Please sign in to comment.