-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
51 lines (40 loc) · 1.38 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
39
40
41
42
43
44
45
46
47
48
49
50
51
// Dependencies
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
// Initialize Express
const app = express();
// Sets the port for the server to listen on
const PORT = process.env.PORT || 3000;
// Use body-parser for handling form submissions
app.use(bodyParser.urlencoded({ extended: true }));
// Sets up the Express app to handle data parsing
app.use(express.urlencoded({extended: true }));
app.use(express.json());
//Sets the server to use the public directory for static assets
app.use(express.static(path.join(__dirname, 'public')));
// app.use(express.static('public'));
// Routes
require('./routes/api-routes-item.js')(app);
require('./routes/api-routes-trips.js')(app);
require('./routes/api-routes-user.js')(app);
require('./routes/html-routes.js')(app);
//Set up promises with mongoose
mongoose.Promise = global.Promise;
//Connect to the Mongo DB
mongoose.connect(
process.env.MONGODB_URI || "mongodb://packit:[email protected]:23454/heroku_hghvcwbh", {
useMongoClient: true
}
);
// Connect for testing.
// mongoose.connect(
// process.env.MONGODB_URI || "mongodb://localhost:27017",
// { useMongoClient: true }
// );
// Starts our server on the predefined PORT
app.listen(PORT, function () {
console.log(`App is now listening on PORT ${PORT}`)
})
module.exports = app;