-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
31 lines (26 loc) · 1020 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
var express = require('express')
var app = express()
var port = process.env.PORT || 3000
var mongoose = require('mongoose')
var bodyParser = require('body-parser')
var router = express.Router()
var path = require('path')
mongoose.Promise = global.Promise; //deprecation warning goes before appRoutes
var appRoutes = require('./app/routes/api')(router)
app.use(bodyParser.json()) //for parsing the json
app.use(bodyParser.urlencoded({ extended: true })) //for parse application/x-www-form-urlencoded
app.use(express.static(__dirname + '/public'))
app.use('/api', appRoutes) //to deconflict te backend and the frontend routes
mongoose.connect('mongodb://localhost:27017/hrbitech', function(err) {
if (err) {
console.log('not connected to the db', err)
} else {
console.log('connected to Mongo');
}
})
app.get('*', function(req, res) {
res.sendFile(path.join(__dirname + '/public/app/views/index.html'))
})
app.listen(port, function() {
console.log('server is running on', port)
})