-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (41 loc) · 1.04 KB
/
index.js
File metadata and controls
49 lines (41 loc) · 1.04 KB
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
const express = require('express')
const cors = require('cors')
const mongoose = require('mongoose');
const app = express()
const cookieParser = require('cookie-parser')
require('dotenv').config()
const userRoute = require('./routes/userRoute')
const todosRoute = require('./routes/todosRoute')
const port = process.env.PORT || 5001
//middleware
app.use(
cors({
origin: [
"http://localhost:5173",
"https://todo-app-10423.web.app",
"http://localhost:4173",
],
credentials: true,
})
);
app.use(express.json())
app.use(cookieParser())
app.get('/', (req, res) => {
return res.send("Server is running...")
})
async function connectDB() {
try {
await mongoose.connect(process.env.MONGO_URI)
console.log('MongoDB connected...')
} catch (error) {
console.error(error.message)
process.exit(1)
}
}
connectDB()
//routes
app.use('/api', userRoute)
app.use('/api', todosRoute)
app.listen(port, () => {
console.log(`Server is running on port ${port}`)
})