connect db
This commit is contained in:
20
index.html
Normal file
20
index.html
Normal file
@@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
<script src="https://libs.cdnjs.net/jquery/3.7.1/jquery.min.js"></script>
|
||||
<script>
|
||||
$(document).ready(() => {
|
||||
$.getJSON('/ten', (data) => {
|
||||
$('#content').text(JSON.stringify(data));
|
||||
})
|
||||
})
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="content"></div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -11,9 +11,7 @@ module.exports = {
|
||||
env: {
|
||||
"NODE_ENV": "production",
|
||||
"PORT": 80,
|
||||
"DATABASE_URL": "localhost:27017",
|
||||
"DATABASE_USER": "labplus_admin",
|
||||
"DATABASE_PASSWORD": "******",
|
||||
"DATABASE_URI": "mongodb://USERNAME:PASSWORD@localhost:27017",
|
||||
}
|
||||
}]
|
||||
}
|
||||
11
src/index.js
11
src/index.js
@@ -8,16 +8,9 @@ dotenv.config()
|
||||
const app = Express()
|
||||
const PORT = process.env.PORT || 8080
|
||||
|
||||
// Database Connect String
|
||||
const DB_URL = process.env.DATABASE_URL
|
||||
const DB_USERNAME = process.env.DATABASE_USERNAME
|
||||
const DB_PASSWORD = process.env.DATABASE_PASSWORD
|
||||
const DB_NAME = "labplus"
|
||||
|
||||
const DATABASE_URI = `mongodb://${DB_USERNAME}:${DB_PASSWORD}@${DB_URL}/${DB_NAME}`
|
||||
|
||||
mongoose.connect(DATABASE_URI)
|
||||
mongoose.connect(process.env.DATABASE_URI)
|
||||
const db = mongoose.connection
|
||||
|
||||
db.on("error", (error) => console.error(error))
|
||||
db.once("open", () => console.log("Connected to Database"))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user