-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
41 lines (32 loc) · 1018 Bytes
/
app.js
File metadata and controls
41 lines (32 loc) · 1018 Bytes
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
const express = require("express");
const app = express();
const api = require("./api");
const morgan = require("morgan"); // http request logger middleware
const bodyParser = require("body-parser");
const cors = require("cors");
app.set("port", process.env.PORT || 8081);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cors());
app.use("/api", api);
app.use(express.static("static"));
app.use(morgan("dev"));
app.use((req, res) => {
const err = new Error("not Found");
console.log(err);
err.status = 404;
res.json({ error: err });
});
// Connect to mongoose
const mongoose = require("mongoose");
mongoose.connect("mongodb://localhost:27017/virtualstandups", {
useNewUrlParser: true
});
const db = mongoose.connection;
db.on("error", console.error.bind(console, "connection error:"));
db.once("open", () => {
console.log("Connected to MongoDB");
app.listen(app.get("port"), () => {
console.log("app listening on port " + app.get("port"));
});
});