-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.js
32 lines (23 loc) · 734 Bytes
/
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
var express = require('express'),
mongoose = require('mongoose'),
bodyParser = require('body-parser');
var db;
if(process.env.ENV == 'Test'){
db = mongoose.connect('mongodb://localhost/bookAPI_test');
} else {
db = mongoose.connect('mongodb://localhost/bookAPI');
}
var Book = require('./models/bookModel');
var app = express();
var port = process.env.PORT || 3000;
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
var bookRouter = require('./routes/bookRouter')(Book);
app.use('/api/books', bookRouter);
app.get('/', function (req, res) {
res.send('Welcome to my API');
});
app.listen(port, function () {
console.log('Running on port: ' + port);
});
module.exports = app;