-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
37 lines (30 loc) · 1.09 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
const express = require('express');
const app = express();
const cors = require('cors');
const dotenv = require('dotenv').config();
const HTTP_PORT = process.env.HTTP_PORT || 5050;
const trackingService = require('./routes/TrackingRoute.js');
const contactService = require('./routes/ContactRoute.js');
const userService = require('./routes/UserRoute.js')
const mongoose = require('mongoose');
app.use(express.json());
app.use(cors({
origin:['http://localhost:3000','https://ordertracking-app.vercel.app'],
credentials:true,
}));
app.use('/api/tracking',trackingService);
app.use('/api/contact',contactService);
app.use('/api/user',userService);
app.get('/',(req,res)=>{
res.json("Hello To Order Tracking App")
});
// Connect to MongoDB
mongoose.connect(process.env.URI,{useNewUrlParser:true}) // return new connection
const connection = mongoose.connection;
connection.once('open',()=>{
console.log("MongoDB database connection established successfully");
app.listen(HTTP_PORT,()=>{console.log(`Listening to Port ${HTTP_PORT}`)});
})
connection.once('error',(err)=>{
console.log(err);
})