-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (26 loc) · 805 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
require('dotenv').config()
const express = require('express')
const App = express()
const CourseRouter = require('./Routers/Course')
const AuthRouter = require('./Routers/Auth')
const mongoose = require('mongoose')
const cors = require('cors')
const path = require('path')
App.use(express.json())
App.use(express.static(path.resolve(__dirname,'dist')))
App.use(cors())
App.use('/api/courses', CourseRouter)
App.use('/auth', AuthRouter)
App.use('*', (req, res, next) => {
res.sendFile(path.resolve(__dirname,'dist/index.html'))
})
main().catch(err => console.log(err));
async function main() {
await mongoose.connect(process.env.MONGO_URI);
console.log("database connected")
}
App.listen(process.env.PORT, () => {
console.log(
`server is listening ${__dirname, process.env.PORT}`
);
});