-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.mjs
43 lines (31 loc) · 939 Bytes
/
server.mjs
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
import express from 'express';
import colors from 'colors';
import dotenv from 'dotenv'
import morgan from 'morgan';
import cors from 'cors'
import connectDB from './config/db.mjs';
import authRoutes from './routes/auth.mjs';
import categoryRoute from './routes/categoryRoute.mjs'
import productRoute from './routes/productRoute.mjs'
dotenv.config();
// DB connection
connectDB()
const app = express();
// middleware functions here
app.use(cors({
origin: [ 'http://localhost:3000'],
credentials: true,
}));
app.use(express.json());
app.use(morgan('dev'));
// routes
app.use('/api/v1/auth', authRoutes);
app.use('/api/v1/category', categoryRoute);
app.use('/api/v1/product', productRoute);
app.get('/', (req, res) => {
res.send('API is running');
})
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
console.log(`Server running on ${process.env.MODE_DEV} mode on port ${PORT}`.yellow.bold);
})