-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (26 loc) · 837 Bytes
/
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
const express = require("express");
const mongoose = require("mongoose");
const homeRoute = require("./routes/home");
const club = require("./models/Club");
const bodyParser = require("body-parser");
const app = express();
const port = 3000;
mongoose.connect("mongodb://127.0.0.1:27017/nodejs_crud", {
useNewUrlParser: true,
});
const db = mongoose.connection;
db.on("error", () => console.log("NOT working"));
db.once("open", () => {
console.log("Connection is done sucessfully!");
});
//MIDDLEWARE
app.set("view engine", "ejs");
app.use(express.static("public"));
app.use(bodyParser.urlencoded({ extended: false }));
// parse application/json
app.use(bodyParser.json());
//Routing
app.use("/", homeRoute);
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});