-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateAdmin.js
More file actions
39 lines (32 loc) · 991 Bytes
/
Copy pathcreateAdmin.js
File metadata and controls
39 lines (32 loc) · 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import mongoose from "mongoose";
import dotenv from "dotenv";
import Admin from "./models/Admin.js";
import connectDB from "./config/db.js";
dotenv.config();
const createAdmin = async () => {
try {
// Connect to database
await connectDB();
// Check if admin already exists
const existingAdmin = await Admin.findOne({ username: "admin" });
if (existingAdmin) {
console.log("❌ Admin already exists!");
process.exit(1);
}
// Create new admin
const admin = new Admin({
username: "devacademy",
password: "dev@67676" // This will be automatically hashed
});
await admin.save();
console.log("✅ Admin created successfully!");
console.log("Username: admin");
console.log("Password: admin123");
console.log("You can now login using these credentials");
process.exit(0);
} catch (error) {
console.error("❌ Error creating admin:", error.message);
process.exit(1);
}
};
createAdmin();