-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
51 lines (42 loc) · 1.74 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//////////////////////////////////////
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var moment = require('moment');
var ejsLint = require('ejs-lint');
var app = express();
//PORT////////////////////////////////////////////////
var port = process.env.PORT || 3000;
var mongoDBURI = process.env.MONGODB_URI || 'mongodb://localhost:27017/project2'
//DATABASE////////////////////////////////////////////
mongoose.connect(mongoDBURI);
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error'));
db.once('open', function(){
console.log('DB: Connected');
});
//MIDDLEWARE//////////////////////////////////////////
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use(methodOverride('_method'));
app.use(express.static('public'));
//CONTROLLERS/////////////////////////////////////////
var unitsController = require('./controllers/unitController');
app.use('/units', unitsController);
var deliveriesController = require('./controllers/deliveryController');
app.use('/deliveries', deliveriesController);
var transactionsController = require('./controllers/transactionController');
app.use('/transactions', transactionsController);
var customersController = require('./controllers/customerController');
app.use('/customers', customersController);
var dashController = require('./controllers/dashController');
app.use('/dash', dashController);
//ROOT ROUTE//////////////////////////////////////////
app.get('/', function(req, res){
res.redirect('/dash');
});
//LISTENER/////////////////////////////////////////////
app.listen(port, function(){
console.log('UNITS APP RUNNING');
});