-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
47 lines (38 loc) · 1.08 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
46
47
import express from 'express';
import mongoose from 'mongoose';
import data from './data';
import userRouter from './routers/userRouter.js';
import productRouter from './routers/productRouter.js';
import categoryRouter from './routers/categoryRouter.js';
import { } from 'dotenv/config';
const app = express();
try {
mongoose.connect(process.env.DATABASE, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
});
console.log('db connected.')
} catch (err) {
console.log(error.reason)
}
// app.get("/api/products", (req, res) => {
// res.send(data.products);
// });
// app.get("/api/sections", (req, res) => {
// res.send(data.sections);
// });
// ROUTES MIDDLEWARE
app.use('/api/users', userRouter);
app.use('/api/products', productRouter);
app.use('/api/category', categoryRouter);
app.get("/", (req, res) => {
res.send('Server is ready');
});
app.use((err, req, res, next) => {
res.status(500).send({ message: err.message });
})
const port = process.env.PORT || 5600;
app.listen(port, () => {
console.log(`server started at localhost:${port}`)
});