-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
43 lines (30 loc) · 1.04 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
/** @format */
const express = require("express");
const colors = require("colors");
const path = require("path");
const crudOperations = require("./routes/crud");
const connectDB = require("./config/db");
var methodOverride = require("method-override");
const morgan = require("morgan");
const engine = require("ejs-mate");
connectDB(); // Database connection
const app = express();
app.engine("ejs", engine);
app.set("view engine", "ejs");
app.set("views", path.join(__dirname, "views"));
app.use(express.urlencoded({ extended: true }));
app.use(methodOverride("_method"));
app.use(morgan("tiny"));
app.use(crudOperations); //Router Middleware
// Error Handling Middleware
app.all('*', (err, req, res, next) => {
next(new ErrorHandler('Page not found', 404))
})
app.use((err, req, res, next) => {
const { statusCode = 500 } = err;
if (!err.message) err.message = 'Something went Wrong...'
res.status(statusCode).render('campgrounds/notFound', { err })
});
app.listen(3000, () => {
console.log("Serving on Port 3000".bgMagenta.white);
});