-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
46 lines (37 loc) · 1.18 KB
/
server.js
File metadata and controls
46 lines (37 loc) · 1.18 KB
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
46
// server.js
// BASE SETUP
// ==============================================
var express = require('express');
var app = express();
var path = require('path');
var port = process.env.PORT || 8080;
// ROUTES
// ==============================================
var fs = require('fs');
var obj;
fs.readFile('data.json', 'utf8', function (err, data) {
if (err) {
throw err;
};
obj = JSON.parse(data);
console.log(obj)
});
app.set('view engine', 'html');
app.engine('html', require('ejs').renderFile);
// sample route with a route the way we're used to seeing it
app.get('/', function(req, res) {
// res.send("Test");
app.use(express.static(path.join(__dirname)));
res.render(path.join(__dirname + '/index.html'), res.json(obj));
res.render(path.join(__dirname + '/index.html'));
});
// sample route with a route the way we're used to seeing it
app.get('/blog', function(req, res) {
app.use(express.static(path.join(__dirname)));
res.render(path.join(__dirname + '/thoughts.html'));
});
// we'll create our routes here
// START THE SERVER
// ==============================================
app.listen(port);
console.log('Magic happens on port ' + port);