forked from Mayanwolfe/Full-stack-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
38 lines (32 loc) · 915 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
33
34
35
36
37
38
const express = require('express')
const app = express()
const cors = require('cors')
const MongoClient = require('mongodb').MongoClient
require('dotenv').config()
const PORT = 8000
let db,
dbConnectionString = process.env.DB_STRING,
dbName = 'sample_mflix',
collection
MongoClient.connect(dbConnectionString)
.then(client => {
console.log(`Connected to Database`)
db = client.db(dbName)
collection = db.collection('movies')
})
app.set('view engine', 'ejs')
app.use(express.static('public'))
app.use(express.urlencoded({extended:true}))
app.use(express.json())
app.use(cors())
app.get('/', async (request, response) => {
try {
response.render('index.ejs')
} catch (error) {
response.status(500).send({message: error.message})
}
})
//PORT = 8000
app.listen(process.env.PORT || PORT, () => {
console.log(`Server is running on port`)
})