-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.js
27 lines (26 loc) · 838 Bytes
/
server.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
require("dotenv").config();
const express = require("express");
const mongoose = require("mongoose");
const { imageRouter } = require("./routes/imageRouter");
const { userRouter } = require("./routes/userRouter");
const app = express();
const { MONGO_URI, PORT } = process.env;
const { authenticate } = require("./middleware/authentication");
mongoose
.connect(MONGO_URI, {
useCreateIndex: true,
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log("MongoDB Connected.");
app.use("/uploads", express.static("uploads"));
app.use(express.json());
app.use(authenticate);
app.use("/images", imageRouter);
app.use("/users", userRouter);
app.listen(PORT, () =>
console.log("Express server listening on PORT " + PORT)
);
})
.catch((err) => console.log(err));