-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
38 lines (31 loc) · 866 Bytes
/
server.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
// Import dependencies
const express = require("express");
const logger = require("morgan");
const mongoose = require("mongoose");
const compression = require("compression");
// Set up express
const PORT = process.env.PORT || 3001;
const app = express();
// Set up morgan logs
app.use(logger("dev"));
// Use compression and sets up data parsing
app.use(compression());
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
// Serve static files
app.use(express.static("public"));
// Set up mongoose connection
mongoose.connect(
process.env.MONGODB_URI || 'mongodb://localhost/budget',
{
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false
}
);
// Set up express routes
app.use(require("./routes"));
app.listen(PORT, () => {
console.log(`App running on port ${PORT}!`);
});