-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
36 lines (28 loc) · 824 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
36
require("express-async-errors");
const express = require("express");
const mongoose = require("mongoose");
require("dotenv").config();
// routing
const authRoutes = require("./routes/auth");
const blogRoutes = require("./routes/blog");
// middlewares
const authMiddleware = require("./middlewares/auth");
const errorHandler = require("./middlewares/error-handler");
const app = express();
app.use(express.json());
app.use("/api/auth", authRoutes);
app.use("/api/posts", authMiddleware, blogRoutes);
app.use(errorHandler);
const port = process.env.PORT || 8000;
const start = async () => {
try {
await mongoose.connect(process.env.MONGO_URI);
app.listen(port, () => {
console.log("Speak for the app is listening");
});
} catch (err) {
console.log(err);
}
};
start();
module.exports = app;