-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
30 lines (24 loc) · 762 Bytes
/
server.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
var express = require('express'),
fs = require('fs');
// App entry point
var app = express();
const PORT = process.env.PORT || 3000;
app.use(function (req, res, next){
if (req.headers['x-forwarded-proto'] === 'https') {
res.redirect('https://' + req.hostname + req.url);
} else {
next();
}
});
app.use(express.static('public'));
app.listen(PORT, function() {
console.log('Express server is up on port ' + PORT + '.');
});
var myWrite = function myWrite(data) {
fs.appendFile('./public/data/results.txt', data, function (err) {
if (err) { console.log('There was an error writing the file.') }
});
};
myWrite('Adding a new line\n');
myWrite('Adding another line\n');
myWrite('Adding this here final line\n');