Skip to content

Commit 969dbc9

Browse files
committed
feat: added server configuration. added mongoose. connect server. get contacts from database
1 parent 0734321 commit 969dbc9

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

models/Contact.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
import { Schema, model } from "mongoose";
22

33
const contactSchema = new Schema({
4-
name: String,
5-
email: String,
6-
phone: String,
7-
favorite: Boolean,
4+
name: {
5+
type: String,
6+
required: [true, "Set name for contact"],
7+
},
8+
email: {
9+
type: String,
10+
},
11+
phone: {
12+
type: String,
13+
},
14+
favorite: {
15+
type: Boolean,
16+
default: false,
17+
},
818
});
919

1020
const Contact = model("contact", contactSchema);

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@
3737
"eslint-plugin-import": "2.25.3",
3838
"eslint-plugin-node": "^11.1.0",
3939
"eslint-plugin-promise": "5.2.0",
40-
"nodemon": "2.0.15"
40+
"nodemon": "^2.0.15"
4141
}
4242
}

server.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ const { DB_HOST, PORT = 3000 } = process.env;
77
mongoose
88
.connect(DB_HOST)
99
.then(() => {
10+
console.log("Database connection successful");
1011
app.listen(PORT, () => {
1112
console.log(`Server running. Use our API on port: ${PORT}`);
1213
});
1314
})
1415
.catch((error) => {
15-
console.log(error.message);
16+
console.error("MongoDB connection error:", error);
1617
process.exit(1);
1718
});

0 commit comments

Comments
 (0)