-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
73 lines (63 loc) · 1.5 KB
/
config.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const mongoose = require("mongoose");
require('dotenv').config();
const URI = process.env.MONGODB_URI;
const connect = mongoose.connect(URI);
if (!URI) {
console.error('MONGODB_URI is not defined');
process.exit(1); // Exit the application with an error code
}
async function connectToDatabase() {
try {
await mongoose.connect(URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
console.log('Database connected successfully');
} catch (error) {
console.error('Database connection error:', error.message);
process.exit(1);
}
}
connectToDatabase();
const LoginSchema = new mongoose.Schema({
name: {
type: String,
required: true
},
password: {
type: String,
required: true
}
});
const LoginModel = mongoose.model("users", LoginSchema);
const SignupSchema = new mongoose.Schema({
name: {
type: String,
required: true
},
password: {
type: String,
required: true
},
});
const SignupModel = mongoose.model("signups", SignupSchema);
const CarSchema = new mongoose.Schema({
name: {
type: String,
required: true
},
model: {
type: Number,
required: true
},
price: {
type: Number,
required: true
},
manufactureYear: {
type: Number,
required:true
},
})
const CarModel = mongoose.model("cars", CarSchema);
module.exports = { LoginModel, SignupModel, CarModel };