-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (26 loc) · 741 Bytes
/
server.js
File metadata and controls
32 lines (26 loc) · 741 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
import express from 'express'
import mongoose from 'mongoose'
import userRouter from './routes/userroute.js'
import productRouter from './routes/product.js'
import cartRouter from './routes/cart.js'
import {config} from 'dotenv'
config({path:'.env'})
const app=express()
const port=process.env.PORT
mongoose.connect(
process.env.MONGO_URL,
{
dbName:"e_commerce_api"
}
).then(()=>{console.log('mongodb is connected')})
.catch((err)=>console.log(err))
//user api
app.use(express.json()); //used to decrypt req.body
app.use('/api/user',userRouter)
//product api
app.use('/api/product',productRouter)
//cart api
app.use('/api/cart',cartRouter)
app.listen(port,()=>{
console.log(`port is running at ${port}`)
})