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
216f9dfb
Commit
216f9dfb
authored
Apr 08, 2026
by
AravindR-K
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: implement MongoDB connection and default admin user initialization
parent
80147bab
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
7 deletions
+5
-7
Backend/config/db.js
Backend/config/db.js
+5
-7
No files found.
Backend/config/db.js
View file @
216f9dfb
const
mongoose
=
require
(
'
mongoose
'
);
const
mongoose
=
require
(
'
mongoose
'
);
const
User
=
require
(
'
../models/User
'
);
const
User
=
require
(
'
../models/User
'
);
const
bcrypt
=
require
(
'
bcryptjs
'
);
const
createAdmin
=
async
()
=>
{
const
createAdmin
=
async
()
=>
{
const
adminExists
=
await
User
.
findOne
({
email
:
'
admin@
test
.com
'
});
const
adminExists
=
await
User
.
findOne
({
email
:
'
admin@
quizapp
.com
'
});
if
(
!
adminExists
)
{
if
(
!
adminExists
)
{
const
hashedPassword
=
await
bcrypt
.
hash
(
'
admin123
'
,
10
);
// Pass plain password - User model's pre-save hook will hash it
await
User
.
create
({
await
User
.
create
({
name
:
'
Admin
'
,
name
:
'
Admin
'
,
email
:
'
admin@
test
.com
'
,
email
:
'
admin@
quizapp
.com
'
,
password
:
hashedPassword
,
password
:
'
admin123
'
,
role
:
'
admin
'
role
:
'
admin
'
});
});
console
.
log
(
'
Default admin created
'
);
console
.
log
(
'
Default admin created
: admin@quizapp.com / admin123
'
);
}
}
};
};
const
connectDB
=
async
()
=>
{
const
connectDB
=
async
()
=>
{
...
...
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