-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (28 loc) · 961 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
const express = require('express');
const path = require('path');
const dotenv = require('dotenv').config();
const { MongoClient, ServerApiVersion, ObjectId } = require('mongodb');
const mongo = new MongoClient(process.env.MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
mongo.connect();
const db = mongo.db('Kale').collection('Messages')
module.exports.db = db;
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
// Back End
const { post, get, del } = require('./methods');
app.post('/messages', post);
app.get('/messages/:id', get);
app.delete('/messages/:id', del);
// Front End
app.set('view engine', 'ejs');
app.use(express.static('public'));
app.get('/', (req, res) => {
res.render('index');
})
app.get('/:id', (req, res) => {
res.render('message');
});
app.listen(443, () => {
console.log('✅ 🥬Kale is now live on port 443!');
});