-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
39 lines (31 loc) · 996 Bytes
/
Copy pathserver.js
File metadata and controls
39 lines (31 loc) · 996 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
32
33
34
35
36
37
38
39
const express = require('express')
const mongoose = require('mongoose')
const path = require('path')
const cors = require('cors')
//APIs
const usersApi = require("./server/routes/user.route")
const categoriesApi = require('./server/routes/category.route')
//use process.env.... <npm i dotenv>
const dotenv = require('dotenv')
dotenv.config()
const app = express()
app.use(express.json())
app.use(cors())
//server Index page
app.use(express.static(path.join(__dirname, "server/www")));
//RUN <npm run startDev> to run the server
app.listen(process.env.PORT, ()=>{
console.log(`Server listening on port: ${process.env.PORT} ...`)
})
//connect to mongo
mongoose.connect(
"mongodb+srv://prisma:prisma@prisma.kni8ffr.mongodb.net/dashboard-angular?retryWrites=true&w=majority"
).then(()=>{
console.log("Connected to MongoDB")
}).catch((err)=>{
console.log(`Connection failed ${err}`)
})
//use users API
app.use("/users", usersApi)
//use users API
app.use("/categories", categoriesApi)