-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
35 lines (24 loc) · 1022 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
const express = require("express");
require("./connectMongo");
const path = require("path");
// const Route = require("./routes/userRoutes");
const userRoutes = require("./routes/userRoutes");
const petRoutes = require("./routes/petRoutes");
const cors = require( "cors" );
const app = express();
const PORT = process.env.PORT || 4000;
app.use( cors( { origin: "*" } ) )
// needed urlencoded to see data in req.body and for getting files
app.use( express.urlencoded( { extended: true } ) );
app.use(express.json());
// use public folder for storing images there
app.use(express.static(path.join(__dirname, "./public")));
app.get("/", (req, res, next) => {
res.send(`hello sexy paw --- use "/users" to get all user! --- use "/pets" to get all pets! `);
})
app.use("/users", userRoutes);
app.use("/pets", petRoutes);
app.use((err, req, res, next) => {
res.status(err.status || 500).send({ success: false, message: err.message });
});
app.listen(PORT, () => console.log("Server running on port: ", PORT));