-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (37 loc) · 1.58 KB
/
index.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
//=====================Importing Module and Packages=====================//
const express = require('express');
const route = require('./src/routes/route.js');
const { default: mongoose } = require('mongoose');
const moment = require('moment');
const app = express();
const multer= require("multer");
app.use(express.json());
app.use( multer().any())
mongoose.connect("mongodb+srv://raj_3028:kWaM507ps0Icsdg0@cluster0.pw23ckf.mongodb.net/group16Database", {
useNewUrlParser: true
})
.then(() => console.log("MongoDb is Connected."))
.catch(error => console.log(error))
//===================== Global Middleware for Console the Date, Time, IP Address and Print the perticular API Route Name when you will hit that API =====================//
app.use(
function globalMiddleWare(req, res, next) {
const today = moment();
const formatted = today.format('YYYY-MM-DD hh:mm:ss');
console.log("----------------")
console.log("Date:-", formatted);
console.log("IP Address:-", req.ip);
console.log("API Route Info:-", req.originalUrl);
next()
}
)
//===================== Global Middleware for All Route =====================//
app.use('/', route)
//===================== It will Handle error When You input Wrong Route =====================//
app.use(function (req, res) {
var err = new Error("Not Found.")
err.status = 404
return res.status(404).send({ status: "404", msg: "Path not Found." })
})
app.listen(process.env.PORT || 3000, function () {
console.log('Express App Running on Port: ' + (process.env.PORT || 3000))
});