-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
34 lines (29 loc) · 892 Bytes
/
index.js
File metadata and controls
34 lines (29 loc) · 892 Bytes
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
const express = require("express");
const mongoose = require("mongoose");
const swaggerUI = require("swagger-ui-express")
const morgan = require("morgan")
const router = require("./routes/route");
require('dotenv').config()
//constructors
const app = express();
app.use(express.json())
app.use(express.urlencoded({extended: true}))
app.use(morgan('dev'))
app.use('/api', router)
//Create swagger docs
const swaggerDocument = require('./swagger.json');
app.use('/api-docs', swaggerUI.serve, swaggerUI.setup(swaggerDocument))
//Connect to MongoDB
try {
// Connect to the MongoDB cluster
mongoose.connect(
process.env.MONGODB_URI,
{ useNewUrlParser: true, useUnifiedTopology: true },
() => console.log(" Mongoose is connected")
);
} catch (e) {
console.log("could not connect");
}
app.listen(3000, () => {
console.log("Listening on PORT 3000")
})