-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
32 lines (27 loc) · 822 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
28
29
30
31
32
require("dotenv").config();
const express = require("express");
const mongoose = require("mongoose");
const morgan = require('morgan');
const helmet = require('helmet');
const routes = require("./routes/routes.js");
const app = express();
app.use(helmet());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(morgan("tiny"));
app.use("/", routes);
const execute = async () => {
try {
await mongoose.connect(process.env.DBURL, {
useNewUrlParser: true,
useUnifiedTopology: true
})
console.log("DB connected!");
app.listen(process.env.PORT || 8080, () => {
console.log(`Server starting on port: ${process.env.PORT || 8080}`)
})
} catch (error) {
console.log("Error : ", error);
}
}
execute();