-
Notifications
You must be signed in to change notification settings - Fork 1
/
oldapp.js
48 lines (37 loc) · 1.14 KB
/
oldapp.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
const express = require("express");
const path = require("path");
const methodOverride = require("method-override");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const app = express();
// Load routes
const galaries = require("./routes/galarie");
// DB Config
const db = require("./config/database");
// Map global promise - get rid of warning
mongoose.Promise = global.Promise;
// Connect to mongoose
mongoose
.connect(db.mongoURI, {
useMongoClient: true
})
.then(() => console.log("MongoDB Connected..."))
.catch(err => console.log(err));
// ejs Middleware
app.use(express.static("public"));
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "ejs");
app.use(express.static("uploads"));
// Body parser middleware
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// Static folder
app.use(express.static(path.join(__dirname, "public")));
// Method override middleware
app.use(methodOverride("_method"));
// Use routes
app.use("/", galaries);
const port = process.env.PORT || 5000;
app.listen(port, () => {
console.log(`Server started on port ${port}`);
});