-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (35 loc) · 877 Bytes
/
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
const express = require("express");
const app = express();
const mongoose = require("mongoose");
const imageRoutes = require("./routes/image");
const path = require("path");
require("dotenv").config();
//Connect to database
mongoose
.connect(process.env.MONGO_URI, {
useUnifiedTopology: true,
useNewUrlParser: true,
dbName: process.env.DB_NAME,
})
.then(() => {
console.log("connected to db");
})
.catch(() => {
console.log("Not connected!");
});
process.on("unhandledRejection", (error) => {
console.log("unhandledRejection", error.message);
});
app.use(express.json());
app.use(
express.urlencoded({
extended: true,
})
);
app.use("/image", imageRoutes);
app.listen(process.env.PORT || 8080, function () {
console.log("App running!");
});
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "index.html"));
})