-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
27 lines (22 loc) · 748 Bytes
/
app.js
File metadata and controls
27 lines (22 loc) · 748 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
const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const app = express();
if (process.env.ENV === "Test") {
const db = mongoose.connect("mongod://localhost/bookAPI_Test");
} else {
const db = mongoose.connect("mongodb://localhost/bookAPI");
}
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("Welcome to my NODEMON api!");
});
app.server = app.listen(port, () => {
console.log(`Running on port ${port}`);
});
module.exports = app;