-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
35 lines (26 loc) · 795 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
var express = require('express'),
mongoose = require('mongoose'),
bodyParser = require('body-parser');
// connect to mongodb
var db = mongoose.connect('mongodb://localhost/bookAPI');
// data structure
var Book = require('./models/BookModel');
// initialize express
var app = express();
// set port
var port = process.env.PORT || 3000;
// assign body-parser
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
var bookRouter = require('./Routes/bookRoutes')(Book);
// assign router
app.use('/api/books', bookRouter);
// app.use('/api/authors', authorRouter);
// default utput
app.get('/', function(req, res){
res.send('Welcome to my API');
});
// start listen to porn/live
app.listen(port, function(){
console.log('Gulp is running on PORT: ' + port);
});