-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
35 lines (26 loc) · 953 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
34
35
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const sqlite = require('sqlite3');
const app = express();
if (process.env.ENV === 'Test') {
console.log('this is a TEST');
const db = mongoose.connect('mongodb://localhost/bookAPI_Test');
} else {
const db = mongoose.connect('mongodb://localhost/bookAPI');
}
const port = process.env.PORT || 3000;
const Book = require('./models/bookModel');
// const bookRouter = express.Router(); direct way
// book router module returns route function. We execute it with the Book model.
const bookRouter = require('./routes/bookRouter')(Book);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use('/api', bookRouter);
app.get('/', (req, res) => {
res.send('Welcome to my Nodemon API');
});
app.server = app.listen(port, () => {
console.log(`Running on port ${port}`);
});
module.exports = app;