-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
31 lines (28 loc) · 1.29 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
// creating all my variables
var express = require('express'),
app = express(),
bodyParser = require('body-parser'),
logger = require('morgan'),
cors = require('cors'),
datejs = require('datejs'),
path = require('path'),
port = process.env.PORT || 8081,
apiRoutes = require('./api_routes'),
mongoose = require('mongoose'),
databaseURL = "mongodb://localhost/testUsers"
// Connecting to the mongoose database
mongoose.connect(databaseURL, function(err){
if(err) console.log(err)
console.log("connected to THE MONGODS")
})
// Setting up all the middleware.
app.use(logger('dev')) // <-- logger variable used to log issues to the terminal
app.use(bodyParser.json()) // <-- bodyParser variable used to read through and make json format readable
app.use(bodyParser.urlencoded({extended: true})) // <-- bodyParser variable used to turn the gobbledeegook urls into coherant words
app.use(cors()) // <-- IDK for sure?
app.use('/api/v1', apiRoutes)
app.use(express.static(path.join(__dirname, './public')))
app.listen(port, function (err) {
if(err) console.log(err) // if there is in error connecting to the port, than it will log the error
console.log('Server running on port: ' + port) // if there is no error, we will get this response
})