-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
41 lines (34 loc) · 1.04 KB
/
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
38
39
40
41
const path = require("path");
const express = require("express");
const app = express();
const pics = require("./routes/pics");
const userRouter = require("./routes/userRoutes");
const connectDB = require("./db/connect");
require("dotenv").config();
// viewing engine
app.set("view engine", "ejs");
// app.set("views", path.join(__dirname, "views"));
// serving static files
app.use(express.static(path.join(__dirname, "public")));
app.use(express.urlencoded({ extended: true }));
// middleware
app.use(express.json());
app.get("/", (req, res) => {
res.redirect("/pics");
});
app.use("/pics", pics);
app.use("/users", userRouter);
// const port = process.env.PORT || 3000;
app.set("port", process.env.PORT || 5000);
const start = async () => {
try {
await connectDB(process.env.MONGOURI);
// app.listen(port, console.log(`server is listening on port ${port}...`));
app.listen(app.get("port"), function () {
console.log("Node server is running on port " + app.get("port"));
});
} catch (error) {
console.log(error);
}
};
start();