-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (33 loc) · 1.32 KB
/
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
require('dotenv').config();
//import the necessary modules
const path = require('path');
const express = require('express');
const hbs = require('hbs');
const handlebars_helper = require(`./views/hbs-helper.js`);
const routes = require('./routes/routes.js');
const db = require('./models/db.js');
const repl = require('./models/replicator.js');
const { ping_node } = require('./models/nodes.js');
const { select_query } = require('./models/db.js');
const app = express();
//parse incoming requests with urlencoded payloads
app.use(express.urlencoded({ extended: false }));
//parse incoming json payload
app.use(express.json());
var port = process.env.PORT;
var hostname = process.env.HOSTNAME;
//set the file path containing the static assets
app.use(express.static(path.join(__dirname, 'public')));
//set hbs as the view engine
app.set('view engine', 'hbs');
//set the file path containing the hbs files
app.set('views', path.join(__dirname, 'views'));
//set the file path containing the partial hbs files
hbs.registerPartials(path.join(__dirname, 'views/partials'));
/* The page should only be accessible once the database is connected. */
app.use('/', routes);
app.listen(process.env.PORT, process.env.HOSTNAME, function () {
console.log(`Server is running at http://${hostname}:${port}`);
repl.replicate();
});
module.exports = app;