-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
52 lines (45 loc) · 1.26 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
42
43
44
45
46
47
48
49
50
51
52
const express = require("express");
const app = express();
const PORT = 4000;
const mongoose = require("mongoose");
const { MONGOURI } = require("./keys");
const morgan = require("morgan");
const router = express.Router();
mongoose.connect(MONGOURI, { useNewUrlParser: true, useUnifiedTopology: true });
mongoose.connection.on("connected", () => {
console.log("mongoose db connected");
});
mongoose.connection.on("error", (err) => {
console.log(err);
});
app.use(express.json());
app.use(morgan("dev"));
//routerss
require("./models/user");
require("./models/stories");
app.use(require("./routers/auth"));
require("./models/post");
app.use(require("./routers/post"));
app.use(require("./routers/stories"));
require("./models/user");
app.use(require("./routers/user"));
const middleware = (req, res, next) => {
console.log("middleware is running");
next();
};
app.use(middleware)
app.use(
router.get("/", (req, res) => {
//res.json("for creating post:/createpost(loginreq)\n view all post: /post")
res.json({
post: "/post(loginreq)",
createpost: "/createpost(login req)",
mypost: "/mypost(loginreq)",
signin: "/signin",
signup: "/signup",
});
})
);
app.listen(PORT, () => {
console.log("server is runnig at port", PORT);
});