-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (34 loc) · 949 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
const express = require("express");
const mongoose = require("mongoose");
const chalk = require("chalk");
const cors = require("cors");
const routes = require("./routes");
require("./services/passport");
const { database } = require("./config/keys");
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cors());
app.use(routes);
// Connect to MongoDB
mongoose.set("useCreateIndex", true);
mongoose
.connect(database, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
})
.then(() =>
console.log(`${chalk.green("✓")} ${chalk.blue("MongoDB Connected!")}`)
)
.then(() => {
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
console.log(
`${chalk.green("✓")} ${chalk.blue(
"Server Started on port"
)} ${chalk.bgMagenta(PORT)}`
);
});
})
.catch((err) => console.log(err));