-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
33 lines (29 loc) · 1.16 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
var express = require('express');
var app = express();
var PORT = process.env.PORT || 8000;
var morgan = require('morgan');
var mongoose = require('mongoose');
var User = require('./app/models/user');
var bodyParser = require('body-parser');
var router = express.Router();
var appRoutes = require('./app/routes/api')(router);
var path = require('path');
app.use(morgan('dev')); //middle ware the console logs every req
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({extended: true})); // for parsing application/x-www-form-urlencoded
app.use(express.static(__dirname + '/public'));
app.use('/api', appRoutes);
//establishes connection to DB, the function confirms connection
mongoose.connect('mongodb://heroku_pms48n0c:[email protected]:17821/heroku_pms48n0c', function(err){
if(err){
console.log('Not connected to DB ' + err);
}else{
console.log('Successfully connected to DB');
}
});
app.get('*', function(req, res){
res.sendFile(path.join(__dirname + '/public/app/views/index.html'));
});
app.listen(PORT, function(){
console.log('Running the server on port ' + PORT);
});