-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
35 lines (26 loc) · 1.04 KB
/
app.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
const express = require('express')
const bodyParser = require('body-parser')
const mongoose = require('mongoose')
const errorHandler = require('./services/error-handler')
const ExtendedError = require('./services/error-prototypes').ExtendError
var app = express()
app.use(express.static(__dirname + '/client'))
app.use(bodyParser.json())
app.use(require('./routes/index'))
app.use(require('./routes/product-route'))
app.use(require('./routes/order-route'))
app.use(require('./routes/user-route'))
app.use(errorHandler)
var port = process.env.PORT || 3000
var uristring = 'mongodb://admin:[email protected]:57833/shopping-cart' || //mLab DB
'mongodb://localhost/shopping-cart' //local DB
mongoose.Promise = global.Promise
mongoose.connect(uristring, { useMongoClient: true }, (err, next) => {
if (err) {
next(new ExtendedError('Can\'t connect to database:' + uristring, 500, err))
} else {
console.log('Succeeded connected to: ' + uristring)
}
})
app.listen(port)
console.log('Running on port ' + port)