-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
38 lines (30 loc) · 1.09 KB
/
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
const express = require("express");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const PORT = process.env.PORT || 5000;
// Initialize Express
const app = express();
// Configure middleware
// Use body-parser for handling form submissions
app.use(bodyParser.urlencoded({ extended: true }));
// Use express.static to serve the public folder as a static directory
app.use(express.static("public"));
// If deployed, use the deployed database. Otherwise use the local mongoColors database
const MONGODB_URI =
process.env.MONGODB_URI || "mongodb://localhost/mongoColors";
// Set mongoose to leverage built in JavaScript ES6 Promises
// Connect to the Mongo DB
mongoose.Promise = Promise;
mongoose.connect(MONGODB_URI, {
useCreateIndex: true,
useNewUrlParser: true,
useUnifiedTopology: true
});
// Import routes and give the server access to them.
// Routes
// =============================================================
require("./controller/controller.js")(app);
// Start the server
app.listen(PORT, () =>
console.log(`\nListening on port http://localhost:${PORT}`)
);