-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
45 lines (35 loc) · 984 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
36
37
38
39
40
41
42
43
44
45
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const cors = require('cors');
const mongoose = require('mongoose');
const config = require('./config/database');
const index = require('./routes/index');
//cheching and connecting db
mongoose.connect(config.database,
{
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false
}
)
.then(() => {
console.log("MongoDB is Connected");
})
.catch((error) => {
console.log("MongoDB is not connected because of: " + error);
})
const app = express();
app.set('views',path.join(__dirname,'view'));
app.set('view engine','ejs');
app.use(express.static(__dirname + '/public'));
const urlshort = require('./routes/urlshort');
const port = process.env.PORT || 4000;
app.use(cors());
app.use(bodyParser.json());
app.use('/api',urlshort);
app.use('/',index);
app.listen(port, () =>{
console.log(`Listening on port ${port}`)
});