-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
45 lines (37 loc) · 1.01 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
import express from 'express';
import colors from 'colors';
import dotenv from 'dotenv';
import morgan from 'morgan';
import connect_db from './config/db.js';
import authRoutes from './routes/auth_route.js';
import cors from 'cors';
import categoryRoutes from './routes/categoryRoutes.js';
import productRoutes from './routes/productRoutes.js';
import formidable from 'formidable';
//configure dotenv
dotenv.config();
//database config
connect_db();
//rest object to create apis
const app = express();
//middlewares
app.use(cors());
app.use(morgan('dev'));
app.use(express.json());
//routes
app.use('/api/v1/auth', authRoutes);
app.use('/api/v1/category', categoryRoutes);
app.use('/api/v1/product', productRoutes);
// rest api create
app.get('/', (req, res) => {
res.send('<h1>Welcome to my E-Commerce Application</h1>');
});
//PORT
const PORT = process.env.PORT || 8080;
//run the app
app.listen(PORT, () => {
console.log(
`Server Running on ${process.env.DEV_MODE} mode on port ${PORT}`.bgCyan
.white
);
});