-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
43 lines (24 loc) · 993 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
39
40
const express = require("express");
const mongoose = require('mongoose');
const path = require('path')
const cors = require('cors')
const bodyParser = require('body-parser')
require('dotenv').config({path:__dirname+'/.env'})
const { startAllRoutes } = require("./Routes/allRoutes");
const app = express();
app.use(cors())
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, '/public'),{extensions: ["js","gif","jpg","png"]}))
const mongo = async () =>
{
mongoose.set('strictQuery', false)
try{
return await mongoose.connect( process.env.DB_C, {keepAlive: true,useNewUrlParser: true,useUnifiedTopology: true,}, (arg)=>{console.log("mongoose has connected ")})
}
catch{ err => {console.error('Error connecting to mongo', err)}}
}
mongo()
startAllRoutes(app)
// tell server where to listen
app.listen(4000, () => {console.log(`Server is Listening on port 4000`)});