Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
Daily Thought App
Manage
Activity
Members
Labels
Plan
Issues
4
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
COM3014-Coursework
Daily Thought App
Commits
e30d1ee1
Commit
e30d1ee1
authored
2 years ago
by
Ahmad, Rezwan (PG/T - Comp Sci & Elec Eng)
Browse files
Options
Downloads
Patches
Plain Diff
MongoDB Database Setup
parent
390c697a
No related branches found
Branches containing commit
No related tags found
1 merge request
!9
Create endpoint for user-registration
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
daily-thought-user-service/server/database/conn.js
+16
-0
16 additions, 0 deletions
daily-thought-user-service/server/database/conn.js
daily-thought-user-service/server/server.js
+12
-2
12 additions, 2 deletions
daily-thought-user-service/server/server.js
with
28 additions
and
2 deletions
daily-thought-user-service/server/database/conn.js
0 → 100644
+
16
−
0
View file @
e30d1ee1
import
mongoose
from
"
mongoose
"
;
import
{
MongoMemoryServer
}
from
"
mongodb-memory-server
"
;
async
function
connect
(){
const
mongod
=
await
MongoMemoryServer
.
create
();
const
getUri
=
mongod
.
getUri
();
mongoose
.
set
(
'
strictQuery
'
,
true
)
const
db
=
await
mongoose
.
connect
(
getUri
);
console
.
log
(
"
Database Connected
"
)
return
db
;
}
export
default
connect
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
daily-thought-user-service/server/server.js
+
12
−
2
View file @
e30d1ee1
import
express
from
'
express
'
;
import
cors
from
'
cors
'
;
import
morgan
from
'
morgan
'
;
import
connect
from
'
./database/conn.js
'
const
app
=
express
();
...
...
@@ -16,6 +17,15 @@ app.get('/', (req, res) => {
res
.
status
(
201
).
json
(
"
Home GET Request
"
)
});
app
.
listen
(
port
,
()
=>
{
console
.
log
(
`Server connected to http://localhost:
${
port
}
`
);
// Start server only when we have valid connection
connect
().
then
(()
=>
{
try
{
app
.
listen
(
port
,
()
=>
{
console
.
log
(
`Server connected to http://localhost:
${
port
}
`
);
})
}
catch
(
error
)
{
console
.
log
(
'
Cannot connect to the server
'
)
}
}).
catch
(
error
=>
{
console
.
log
(
"
Invalid database connection...!
"
);
})
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment