-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
32 lines (31 loc) · 1013 Bytes
/
server.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
const express = require('express')
const bodyparser = require('body-parser')
const cors = require('cors')
const mongoose = require('mongoose')
const productRoutes = require('./Routes/productRoutes')
const userRoutes = require('./Routes/userRoutes')
const cartRoutes = require('./Routes/cartRoutes')
//import url
let url = require('./url')
//create rest object
let app = express()
//set JSON as MIME type
app.use(bodyparser.json())
//client is not sending form data -> encoding JSON
app.use(bodyparser.urlencoded({ extended: false }))
//enable CORS -> Cross Origine Resource Sharing -> communication among various ports
app.use(cors())
mongoose.connect(url,{dbName : "mini_project"}).then(()=>{
console.log("Connection successful")
},(errRes)=>{
console.log("Connection Failed - ",errRes)
})
app.use('/',productRoutes)
app.use('/users',userRoutes)
app.use('/carts',cartRoutes)
//create port
let port = 8080
//assign port no
app.listen(port, () => {
console.log('Server listening port no:- ', port)
})