-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcheck.js
More file actions
109 lines (83 loc) · 2.85 KB
/
check.js
File metadata and controls
109 lines (83 loc) · 2.85 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// import express from "express";
// import bodyParser from "body-parser";
// import mongoose from "mongoose";
// import cors from "cors";
// import dotenv from "dotenv";
// import { fetchData } from "./api/fetch.js";
// import userRoutes from "./routes/users.js";
// import user from "./models/user.js";
// const app = express();
// dotenv.config();
// app.use(bodyParser.json({ limit: "30mb", extended: true }));
// app.use(bodyParser.urlencoded({ limit: "30mb", extended: true }));
// app.use(cors());
// app.use("/user", userRoutes);
// const PORT = process.env.PORT || 5000;
// mongoose
// .connect(process.env.CONNECTION_URL, {
// useNewUrlParser: true,
// useUnifiedTopology: true,
// })
// .then(() =>
// app.listen(PORT, () => console.log(`server running on port ${PORT}`))
// )
// .catch((error) => console.log(`${error} did not connected`));
import express from 'express';
import bodyParser from 'body-parser';
import mongoose from 'mongoose';
import dotenv from 'dotenv'
import cors from 'cors';
import userRoutes from './routes/users.js';
const app = express();
dotenv.config();
app.use(bodyParser.json({ limit: '30mb', extended: true }))
app.use(bodyParser.urlencoded({ limit: '30mb', extended: true }))
app.use(cors());
app.use("/user", userRoutes);
// const PORT = process.env.PORT|| 5000;
// mongoose.connect(process.env.CONNECTION_URL, { useNewUrlParser: true, useUnifiedTopology: true })
// .then(() => app.listen(PORT, () => console.log(`Server Running on Port: http://localhost:${PORT}`)))
// .catch((error) => console.log(`${error} did not connect`));
// mongoose.set('useFindAndModify', false);
// setInterval(() => {
// let obj = [];
// fetchData("user").then((data) => {
// obj = data;
// for (let x of obj) {
// // console.log(x);
// if (x.allowed === true) {
// const insertUser = async () => {
// const check = await user.findOne({ email: x.email });
// if (!check) {
// const res = await user.create({
// email: x.email,
// password: x.password,
// name: `${x.firstName} ${x.lastName}`,
// });
// // console.log(res);
// }
// };
// insertUser();
// } else {
// const deleteUser = async () => {
// const res = await user.deleteMany({ email: x.email });
// // console.log(res);
// };
// deleteUser();
// }
// }
// });
// }, 10000);
mongoose.connect(process.env.CONNECTION_URL,{useNewUrlParser:true, useUnifiedTopology: true});
mongoose.connection.on('error',err=>{
console.log('connection failed');
});
mongoose.connection.on('connected',()=>{
console.log('connected successfully with database');
});
app.get('*',(req,res)=>{
res.status(200).json({
message:'bad request'
})
})
export default app ;