-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
44 lines (38 loc) · 1.12 KB
/
server.js
File metadata and controls
44 lines (38 loc) · 1.12 KB
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
40
41
42
43
44
//modulebase approch ES6 file
import express from "express"
import colors from 'colors'
import dotenv from "dotenv"
import morgan from 'morgan'
import connectDB from "./config/db.js"
import authRoutes from './routes/authRoute.js'
import categoryRoutes from './routes/categoryRoutes.js'
import cors from 'cors'
import productRoutes from './routes/productRoutes.js'
import path from "path"
import {fileURLToPath} from 'url';
//configure env
dotenv.config()
//connectDB
connectDB();
//esmodule fix
const __filename=fileURLToPath(import.meta.url);
const __dirname=path.dirname(__filename);
//rest object
const app=express()
//middlewares
app.use(cors())
app.use(express.json())
app.use(morgan('dev'))
app.use(express.static(path.join(__dirname,'./client/build')))
//routes
app.use("/api/v1/auth",authRoutes)
app.use("/api/v1/category",categoryRoutes);
app.use("/api/v1/product",productRoutes)
//rest api
app.use("*",function(req,res){
res.sendFile(path.join(__dirname,'./client/build/index.html'))
})
const port=process.env.PORT
app.listen(port,()=>{
console.log(`server runnig on ${process.env.DEV_MODE} mode on ${port}`.bgCyan.white)
})