-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
31 lines (26 loc) · 835 Bytes
/
server.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
require("dotenv").config();
const express = require("express");
const cors = require("cors");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const app = express();
const { rootHandler } = require("./handlers/root");
const {
createAnimalHandler,
getAnimalsHandler,
updateAnimalHandler,
deleteAnimalHandler,
} = require("./handlers/animals");
mongoose.connect(process.env.MONGODB_CONNECTION);
const host = "http://localhost";
const port = process.env.PORT;
app.use(cors());
app.use(bodyParser.json());
app.get("/", rootHandler);
app.post("/animals", createAnimalHandler);
app.get("/animals", getAnimalsHandler);
app.patch("/animals/:id", updateAnimalHandler);
app.delete("/animals/:id", deleteAnimalHandler);
app.listen(port, () => {
console.log(`Server running on ${host}:${port}`);
});