-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
56 lines (42 loc) · 1.14 KB
/
app.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
50
51
52
53
54
55
56
require("dotenv").config();
const express = require("express");
const app = express();
const PORT = process.env.PORT || 3000;
const dbURI = process.env.MONGO_URI;
//setting up middlewares
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(express.raw());
app.use(express.static("./public"));
app.use(express.static("./uploads"));
// app.use(require("cors")());
require("./router")(app);
// 404 Error Handler
app.all("*", (req, res) => {
res.status(404).json({
status: false,
error: "And Just Like That, You Completely Lost Your Way 😥",
});
});
// connecting to mongodb database
const mongoose = require('mongoose');
mongoose
.connect(dbURI, {
useNewUrlParser:true,
useUnifiedTopology:true
})
.then(()=>{
console.log('This app is connected to the server database');
app.listen(PORT, () => {
console.log(
`Database connected successfully.
Server is running on port ${PORT}
http://localhost:${PORT}`
);
});
})
.catch(err => {
console.log('could not connect to mongoDB', err)
});
module.exports = { app };
require('./router')(app);