-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
52 lines (40 loc) · 1.37 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// [LOAD PACKAGES]
var express = require('express');
var app = express();
const morgan = require("morgan");
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
// [ CONFIGURE mongoose ]
// CONNECT TO MONGODB SERVER
var db = mongoose.connection;
db.on('error', console.error);
db.once('open', function(){
// CONNECTED TO MONGODB SERVER
console.log("Connected to mongod server");
});
mongoose.connect('mongodb://localhost/books');
app.use(morgan("dev"));
app.use('/uploads', express.static('uploads'));
// DEFINE MODEL
var Book = require('./models/book');
var Match = require('./models/match')
// [CONFIGURE APP TO USE bodyParser]
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// [CONFIGURE SERVER PORT]
var port = process.env.PORT || 8080;
// [CONFIGURE ROUTER]
var indexRouter = require('./routes/index')(app)
var booksRouter = require('./routes/books')(app, Book)
const imagesRouter = require("./routes/images");
var contactRouter = require('./routes/contacts');
var matchesRouter = require("./routes/matches")(app, Match)
app.use('/contacts', contactRouter)
app.use('/books', booksRouter);
app.use('/images', imagesRouter);
app.use('/matches', matchesRouter);
app.use('/', indexRouter);
// [RUN SERVER]
var server = app.listen(port, function(){
console.log("Express server has started on port " + port)
});