-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (26 loc) · 862 Bytes
/
index.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
const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const Book = require("./models/bookModel");
const dotenv = require("dotenv");
const bookRouter = require("./routes/bookRouter")(Book);
dotenv.config();
const app = express();
const port = process.env.PORT || 3000;
if (process.env.ENV === "Test") {
console.log("This is test");
const db = mongoose.connect(process.env.TEST_DATABASE_CONNECTION);
} else {
console.log("This is for real");
const db = mongoose.connect(process.env.DATABASE_CONNECTION);
}
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use("/api", bookRouter);
app.get("/", (req, res) => {
res.send("Hello, World!");
});
app.server = app.listen(port, () => {
console.log(`Listening on port ${port}`);
});
module.exports = app;