-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
29 lines (21 loc) · 836 Bytes
/
app.js
File metadata and controls
29 lines (21 loc) · 836 Bytes
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
/* eslint-disable no-param-reassign */
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const app = express();
if (process.env.ENV === 'Test') {
console.log('this is a test database');
const db = mongoose.connect('mongodb://localhost/bookAPI-testdatabase', { useNewUrlParser: true });
} else {
const db = mongoose.connect('mongodb://localhost/bookAPI', { useNewUrlParser: true });
}
const port = process.env.PORT || 3000;
const Book = require('./models/bookModel');
const bookRouter = require('./routes/bookRouter')(Book);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use('/api', bookRouter);
app.server = app.listen(port, () => {
console.log(`Express server started on port: ${port}`);
});
module.exports = app;