-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
33 lines (24 loc) · 791 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
33
'use strict';
const express = require('express');
const mongoose = require('mongoose');
const Book = require('./models/bookModel');
const bodyParser = require('body-parser');
let db;
if (process.env.ENV === 'Test') {
db = mongoose.connect('mongodb://mint-vm:27017/bookAPI_test');
} else {
db = mongoose.connect('mongodb://mint-vm:27017/bookAPI');
}
const app = express();
const port = process.env.PORT || 3000;
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
const bookRouter = require('./routes/bookRoutes')(Book);
app.use('/api/Books', bookRouter);
app.get('/', (req, res) => {
res.send('welcome to the simple node express service');
});
app.listen(port, () => {
console.log('Running on port ' + port);
});
module.exports = app;