-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
49 lines (40 loc) · 1.42 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
48
49
const express = require('express')
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const cors = require('cors');
const mongoose = require('mongoose');
const routes = require('./router/routes');
const port = process.env.PORT || 4000;
const server = express();
// const path = require('path');
server.use(bodyParser.json());
server.use(bodyParser.urlencoded({ extended: false }));
server.use(cors());
server.use(cookieParser());
(async () => {
try {
//mongoDB Connection
await mongoose.connect(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017/feePaymentDB', {
useUnifiedTopology: true,
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
serverSelectionTimeoutMS: 5000,
dbName: 'feePaymentDB'
});
} catch (error) {
console.error(error);
}
})();
const connection = mongoose.connection;
connection.once('open', () => {
console.log("MongoDB database connection established successfully");
})
server.use('/feePaymentDB', routes);
// if (process.env.NODE_ENV === 'production') {
// app.use(express.static( 'client/build' ));
// app.get('*', (req, res) => {
// res.sendFile(path.join(__dirname, 'client', 'build', 'index.html')); // relative path
// });
// }
server.listen(port, () => console.log(`!!!Express Server is Running on port => ${port}`));