-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
44 lines (39 loc) · 1.11 KB
/
main.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
if (process.env.NODE_ENV !== "production") {
require("dotenv").config();
}
const express = require("express");
const app = express();
const PORT = process.env.PORT || 3000;
const cookieParser = require("cookie-parser");
const jwt = require("jsonwebtoken");
const mongoose = require("mongoose");
const dbURI = process.env.DB_URL;
const Grid = require("gridfs-stream");
// ROUTES
const indexRouter = require("./routes/index");
const authRouter = require("./routes/auth");
// DB CONNECTION
async function connectDB() {
await mongoose.connect(dbURI, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
await app.listen(PORT, () => console.log(`Listening on ${PORT}...`));
}
connectDB();
// GRIDFS SETTINGS
const conn = mongoose.connection;
let gfs;
conn.once("open", () => {
gfs = Grid(conn.db, mongoose.mongo);
gfs.collection("fs");
});
// SETTINGS
app.set("view engine", "ejs");
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(__dirname + "/public"));
// ROUTES
app.use("/", indexRouter);
app.use("/auth", authRouter);