Skip to content

Commit

Permalink
move database connection into separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
leightkt committed Apr 7, 2021
1 parent c1ec5f4 commit b6c91b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
20 changes: 6 additions & 14 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ const jwt = require('jsonwebtoken')
const { v1: uuidv1, NIL } = require('uuid');
const reqPromise = require('request-promise')
const mongoose = require('mongoose')
const dotevn = require('dotenv')
dotevn.config()
const uri = `mongodb+srv://${process.env.DB_username}:${process.env.DB_password}@cluster0.f2gkp.mongodb.net/BelayChainNode1?retryWrites=true&w=majority`
const Blockchain = require('./src/Blockchain');
const connectDatabase = require('./database/database')

const { Schema } = mongoose
// const port = process.env.PORT || 9000
const port = process.argv[2]
const corsOptions = {
origin: '*',
methods: 'GET,POST,PUT,PATCH,DELETE'
}
const Blockchain = require('./src/Blockchain');
const bodyParser = require('body-parser');
const app = express();

app.use(cors(corsOptions))
app.use(express.json())

const blockSchema = new Schema({
index: Number,
timestamp: Number,
Expand All @@ -35,14 +35,6 @@ const Block = mongoose.model('Block', blockSchema)
const Node = mongoose.model('Node', nodeSchema)


app.use(cors(corsOptions))
app.use(express.json())

mongoose.connect(uri, {useNewUrlParser: true, useUnifiedTopology: true})
.then(() => console.log("MONGODB CONNECTED"))
.catch(console.error)


let BelayChain = []

const loadBelayChain = () => {
Expand Down
8 changes: 8 additions & 0 deletions database/database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const dotevn = require('dotenv')
dotevn.config()
const uri = `mongodb+srv://${process.env.DB_username}:${process.env.DB_password}@cluster0.f2gkp.mongodb.net/BelayChainNode1?retryWrites=true&w=majority`
const mongoose = require('mongoose')

module.exports = mongoose.connect(uri, {useNewUrlParser: true, useUnifiedTopology: true})
.then(() => console.log("MONGODB CONNECTED"))
.catch(console.error)

0 comments on commit b6c91b3

Please sign in to comment.