-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
27 lines (23 loc) · 686 Bytes
/
Copy pathserver.js
File metadata and controls
27 lines (23 loc) · 686 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
// server.js
const mongoose = require("mongoose");
const app = require("./app");
// Connect to MongoDB
const DB_URI = process.env.MONGO_URI;
const connectToMongoDB = async () => {
try {
await mongoose.connect(DB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
console.log("Connected to MongoDB");
console.log("App ready for use");
} catch (err) {
console.log("Could not connect to MongoDB:", err.message);
}
};
// If not in test mode, connect to MongoDB and start the server
if (process.env.NODE_ENV !== "test") {
connectToMongoDB();
const PORT = 3000;
app.listen(PORT, () => console.log(`Server started on port ${PORT}`));
}