-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
43 lines (34 loc) · 982 Bytes
/
index.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
import express from "express";
import dotenv from "dotenv";
dotenv.config();
import routes from "./routes/index.js";
import { connectDB } from "./config/mongoose.js";
const app = express();
const PORT = process.env.PORT || 8001;
console.log(PORT);
app.use(express.urlencoded({ extended: true }));
// app.use(express.json())
app.set("view engine", "ejs");
app.set("views", "views");
app.use(express.static("./assets"));
app.use("/", routes);
// await connectDB();
// app.listen(port, async (error)=>{
// if(error){
// console.log(`error in running the server :: ${error}`);
// return;
// }
// console.log(`server is running on port :: ${port}`)
// })
const startServer = async () => {
try {
await connectDB();
console.log('MongoDB connected successfully');
app.listen(PORT, () => {
console.log(`server is running on port :: ${PORT}`);
});
} catch (error) {
console.log('Error connecting to MongoDB:', error);
}
};
startServer();