-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
44 lines (35 loc) · 1.03 KB
/
app.js
File metadata and controls
44 lines (35 loc) · 1.03 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
const express = require("express");
const mongoose = require("mongoose");
const cors = require("cors");
const busboy = require("connect-busboy");
const { ValidationError } = require("express-validation");
require('dotenv').config()
const router = require("./routes/mainController");
const app = express()
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(cors());
app.use(busboy());
app.use("/api", router);
app.use(function (err, req, res, next) {
if (err instanceof ValidationError) {
return res.status(err.statusCode).json(err);
}
return res.status(500).json(err);
});
const PORT = process.env.PORT || 3001
const url = `mongodb+srv://Dima1:19022002@cluster0654.ratt8.mongodb.net/todoList?retryWrites=true&w=majority`;
async function start() {
try {
await mongoose.connect(url, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
app.listen(PORT, () => {
console.log(`server is running on port ${PORT}`);
});
} catch (e) {
console.log(e);
}
}
start();