FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Nodejs-REST-API/initDB.js at master · navneetsharma1988/Nodejs-REST-API · GitHub
navneetsharma1988
/
Nodejs-REST-API
Public
forked from
trulymittal/Nodejs-REST-API
Notifications
You must be signed in to change notification settings
Fork
0
Star
2
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Nodejs-REST-API
/
initDB.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
21 lines (16 loc) · 724 Bytes
Breadcrumbs
Nodejs-REST-API
/
initDB.js
Copy path
File metadata and controls
21 lines (16 loc) · 724 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const
mongoose
=
require
(
"mongoose"
)
;
const
connectDB
=
async
(
)
=>
{
try
{
// mongodb://root:123456789@localhost:27017/posts?authSource=admin
const
MONGODB_URL
=
`mongodb://
${
process
.
env
.
MONGO_INITDB_ROOT_USERNAME
}
:
${
process
.
env
.
MONGO_INITDB_ROOT_PASSWORD
}
@
${
process
.
env
.
MONGODB_HOST
}
:
${
process
.
env
.
MONGODB_PORT
}
/
${
process
.
env
.
MONGODB_DB
}
?authSource=
${
process
.
env
.
MONGODB_AUTH_SOURCE
}
`
;
await
mongoose
.
connect
(
MONGODB_URL
,
{
useNewUrlParser
:
true
,
useUnifiedTopology
:
true
,
}
)
;
console
.
log
(
"Connected to mongoDB"
)
;
}
catch
(
err
)
{
console
.
log
(
"Error connecting to mongoDB: "
+
err
.
message
)
;
throw
new
Error
(
"Error connecting to mongoDb"
)
;
}
}
;
module
.
exports
=
connectDB
;
Back
|
FazBrowse Home
|
New Git URL