-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreateAdmin.js
More file actions
38 lines (29 loc) · 905 Bytes
/
Copy pathcreateAdmin.js
File metadata and controls
38 lines (29 loc) · 905 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
import { hash } from "argon2";
import mongodb from "./config/db.js";
import redis from "./config/db.js";
import Admin from "./models/admin.js";
// Function to read user input
const getInput = (prompt) => {
return new Promise((resolve) => {
process.stdout.write(prompt);
process.stdin.once('data', (data) => resolve(data.toString().trim()));
});
};
const main = async () => {
await mongodb.run();
await redis.run();
const admin = {
image: "img/olajide.png",
};
admin.email = await getInput('Enter your Email Address: ');
admin.name = await getInput('Enter your Name: ');
admin.password = await hash(await getInput('Enter your Password: '));
console.log(admin);
const adminModel = new Admin({ ...admin });
await adminModel.save();
process.exit(0);
};
main().catch(err => {
console.error(err);
process.exit(1);
});