forked from Aman0307/Qurl.gq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (32 loc) · 971 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
41
42
if (process.env['DEV']) {
require('dotenv').config();
}
const express = require('express');
const { MongoClient } = require('mongodb');
if (!process.env['MONGO_URI']) {
console.log('Please provide a MONGO_URI environment variable');
process.exit(1);
}
const client = new MongoClient(process.env['MONGO_URI'], {
useNewUrlParser: true,
useUnifiedTopology: true,
});
client.connect((err) => {
if (err) {
console.error(err);
return process.exit(1);
}
console.log('Connected to MongoDB');
});
const urlCollection = client.db('prod').collection('urlCollection');
module.exports = { urlCollection };
const app = express();
app.set('view engine', 'ejs');
app.use(express.static('public'));
app.use(express.json());
app.use(require('./router'));
const WEB_URL = process.env.WEB_URL || 'localhost';
const PORT = process.env.PORT || 8080;
app.listen(PORT, WEB_URL, () => {
console.log(`Listening on port ${PORT}\nhttp://${WEB_URL}:${PORT}`);
});