-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
64 lines (43 loc) · 1.25 KB
/
index.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
53
54
55
56
57
58
59
60
61
62
63
64
const express = require('express');
const { connectMongoDB } = require('./connection');
const morgan = require("morgan");
const fs = require("fs");
const app = express();
const userRouter = require("./routes/user");
const PORT = 5050;
//Connection
connectMongoDB("mongodb://127.0.0.1:27017/himanshu_first_db")
// Schema
//ok
//Middleware or Pluggin
app.use(express.urlencoded({ extended: false })); //Express Middleware
app.use(morgan("tiny"))
app.use((req, res, next) => {
console.log("Hello from middleware 1");
next();
});
app.use((req, res, next) => {
console.log("Hello from middleware 2");
next();
});
app.use((req, res, next) => {
console.log("hello from middleware 3")
fs.appendFile(
"./log.txt",
` \n ${Date.now()}: ${req.ip}: ${req.method}: ${req.path} \n`,
(err, data) => {
next();
}
);
});
//ROUTES
// app.patch("/api/users/:id", (req, res) => {
// // TO DO: Edit the User with ID
// return res.json({status: "pending"})
// })
// app.delete("/api/users/:id", (req, res) => {
// // TO DO: Delete the User with ID
// return res.json({status: "pending"})
// })
app.use("/user", userRouter);
app.listen(PORT, () => console.log(`server listening to port ${PORT}`));