-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
38 lines (31 loc) · 1003 Bytes
/
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
import express from 'express';
import mongoose from 'mongoose';
import uRouter from './Routers/Router1.js';
import pRouter from './Routers/Router2.js';
import dotenv from 'dotenv';
import orderRouter from './Routers/Router3.js';
dotenv.config();
const app = express();
app.use(express.json());
app.use(express.urlencoded({extended: true}))
mongoose.connect(process.env.MONGODB_URL || 'mongodb://localhost/ecommerce', {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true
})
app.use('/api/users' , uRouter);
app.use('/api/items' , pRouter);
app.use('/api/orders' , orderRouter);
app.get('/api/config/paypal', (req, res) => {
res.send(process.env.PAYPAL_CLIENT_ID || 'sb');
})
app.get('/', (req, res) => {
res.send('Server is running');
})
app.use((err, req, res, next) => {
res.status(500).send({message: err.message});
})
const port = process.env.PORT || 5000;
app.listen(port, () => {
console.log(`Server is running at http://localhost:${port}`);
})