-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
52 lines (44 loc) · 1.22 KB
/
server.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
let express = require('express');
let app = express();
let mongoose = require('mongoose');
let morgan = require('morgan');
let bodyParser = require('body-parser');
let port = 3000;
let book = require('./api/routes/book');
let config = require('config');
let options = {
server:{
socketOptions:{
keepAlive:1,
connectTimeoutMS: 30000
}
},
replSet:{
socketOptions:{
keepAlive:1,
connectTimeoutMS: 30000
}
},
useNewUrlParser:true
};
mongoose.connect(config.DBHOST,options);
let database = mongoose.connection;
database.on('error',console.error.bind(console,'Connection Error'));
if(config.util.getEnv('NODE_ENV')==='test'){
app.use(morgan('combined'));
}
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.text());
app.use(bodyParser.json({ type: 'application/json'}));
app.get("/", (req, res) => res.json({message: "Welcome to our Bookstore!"}));
app.route("/book")
.get(book.getBooks)
.post(book.postBook);
app.route("/book/:id")
.get(book.getBook)
.delete(book.deleteBook)
.put(book.updateBook);
app.listen(port);
console.log('Listening on Port' + port);
module.exports = app;