-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
39 lines (31 loc) · 977 Bytes
/
Copy pathapp.js
File metadata and controls
39 lines (31 loc) · 977 Bytes
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
const express = require("express");
const app = express();
const PORT = process.env.PORT || 8000;
const mongoose = require("mongoose");
const { MONGOURI } = require("./config/impKeys");
const auth = require("./routes/auth");
const post = require("./routes/post");
const user = require("./routes/user");
const notice = require("./routes/notice");
require("./models/Signup");
require("./models/post");
require("./models/notice");
// match v7's default (changed from v6 where it's true)
mongoose.set('strictQuery', false);
mongoose.connect(MONGOURI).catch((e) => {
console.error(e);
});
const customMW = (req, res, next) => {
console.log("middleware is executed");
next();
};
app.get("/", (req, res) => {
res.send("Hello from Express!");
});
app.use(express.json());
const routes = [auth, post, user, notice];
routes.forEach((route) => app.use("/api", route));
app.use(customMW);
app.listen(PORT, () => {
console.log(`server is running at port no ${PORT}`);
});