-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
35 lines (29 loc) · 850 Bytes
/
app.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
const express = require("express");
const app = express();
const bodyparser = require("body-parser");
const cookieParser = require("cookie-parser");
const cors = require("cors");
const mongoose = require("mongoose");
require("dotenv").config();
// routes
const apiRoutes = require("./routes/api");
const multer = require("multer");
// DB CONNECTION
mongoose
.connect(process.env.DATABASE, {})
.then(() => {
console.log("DB CONNECTED");
})
.catch((err) => {
console.log(err);
});
app.use(cookieParser());
app.use(express.json());
app.use(multer().array()) //For form-data
app.use(cors());
app.use("/api/", apiRoutes);
const port = process.env.SERVER_PORT || 8000;
const host = process.env.SERVER_HOST || localhost;
app.listen(port, host, () => {
console.log(`Server started http://${host}:${port}`);
});