Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
Hire-Guru
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Rishikumar
Hire-Guru
Commits
2b2cde30
Commit
2b2cde30
authored
Apr 07, 2026
by
AravindR-K
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding central admin inorder to host the quiz
parent
0e98ed63
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
0 deletions
+20
-0
Backend/config/db.js
Backend/config/db.js
+20
-0
No files found.
Backend/config/db.js
View file @
2b2cde30
const
mongoose
=
require
(
'
mongoose
'
);
const
User
=
require
(
'
./models/User
'
);
const
bcrypt
=
require
(
'
bcrypt
'
);
const
createAdmin
=
async
()
=>
{
const
adminExists
=
await
User
.
findOne
({
email
:
'
admin@test.com
'
});
if
(
!
adminExists
)
{
const
hashedPassword
=
await
bcrypt
.
hash
(
'
admin123
'
,
10
);
await
User
.
create
({
name
:
'
Admin
'
,
email
:
'
admin@test.com
'
,
password
:
hashedPassword
,
role
:
'
admin
'
});
console
.
log
(
'
Default admin created
'
);
}
};
const
connectDB
=
async
()
=>
{
try
{
const
conn
=
await
mongoose
.
connect
(
process
.
env
.
MONGODB_URI
);
console
.
log
(
`MongoDB Connected:
${
conn
.
connection
.
host
}
`
);
await
createAdmin
();
}
catch
(
error
)
{
console
.
error
(
`Error:
${
error
.
message
}
`
);
process
.
exit
(
1
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment