-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
28 lines (24 loc) · 945 Bytes
/
index.js
File metadata and controls
28 lines (24 loc) · 945 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
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const path = require('path');
const config = require('./config');
const mongoose = require('mongoose');
const port = config.port || 3000;
app.set("view engine", "ejs");
app.set("views", path.join(__dirname + "/views"));
app.use(express.static(__dirname + '/public'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// Connect to MongoDB
mongoose.connect(config.mongodb, { useNewUrlParser: true }).catch(err => {
console.log("\x1b[31m[ERROR]", `\x1b[0mMongoose Connection Error: \x1b[31m${err}`);
});
// ============================
// Public routes
// ============================
app.get('/', async (req, res) => {
res.render('index');
});
// Launch app on port
app.listen(port, () => console.log('\x1b[31m%s\x1b[0m', '[SERVER]', '\x1b[32m[WEB]\x1b[0m', `Connected @ http://localhost:${port}`));