-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (27 loc) · 835 Bytes
/
index.js
File metadata and controls
31 lines (27 loc) · 835 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
28
29
30
31
import express from 'express'
import 'dotenv/config'
import cors from 'cors'
import connectDB from './db/connect.js'
import usersRouter from './routes/users.js'
import todosRouter from './routes/todos.js'
import routeNotFound from './middlewares/routeNotFound.js'
import errorHandler from './middlewares/errorHandler.js'
const app = express()
app.use(express.static('./public'))
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
//app.use(cors())
app.use('/users',usersRouter)
app.use('/todos', todosRouter)
app.use(routeNotFound)
app.use(errorHandler)
const port = process.env.PORT || 3000
const start = async () => {
try {
await connectDB(process.env.MONGODB_URI)
app.listen(port, () => console.log(`Server is listening on Port: ${port}`))
} catch (error) {
console.log(error)
}
}
start()