-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
38 lines (27 loc) · 867 Bytes
/
app.js
File metadata and controls
38 lines (27 loc) · 867 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
30
31
32
33
34
35
36
37
38
var express = require("express"),
mongoose = require("mongoose"),
bodyParser = require("body-parser");
var db = mongoose.connect('mongodb://localhost/bookAPI', {
useNewUrlParser: true
});
mongoose.connection.once('open', function () {
console.log("Connected to mongodb");
}).on('error', function (error) {
console.log("Failed to connect");
});
var Book = require("./models/bookModel");
var app = express();
var port = process.env.PORT || 3000;
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
bookRouter = require("./Routes/bookRouter.js")(Book);
app.use('/api/books', bookRouter);
// app.use('/api/authors', authorRouter);
app.get("/", function (req, res) {
res.send("Welcom to Node-REST API");
});
app.listen(port, function () {
console.log("Gulp is Running My APP on Port: " + port);
});