-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
37 lines (30 loc) · 917 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
36
37
const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const app = express();
if (process.env.ENV === "Test") {
console.log("Test");
const db = mongoose.connect("mongodb://localhost/bookAPI_Test", {
useNewUrlParser: true,
useUnifiedTopology: true
});
} else {
console.log("Prod");
const db = mongoose.connect("mongodb://localhost/bookAPI", {
useNewUrlParser: true,
useUnifiedTopology: 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.get("/", (req, res) => {
res.send("Aum Namah Shivaya");
});
app.server = app.listen(port, () => {
console.log(`Hara Hara Mahadeva ${port}`);
});
module.exports = app;