forked from burrsutter/node-express-hello
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
42 lines (34 loc) · 899 Bytes
/
app.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
40
41
42
const express = require("express");
const app = express();
const path = require('path');
const os = require('os');
let cnt = 0;
// static page serving
app.use(express.static(path.join(__dirname, 'html')));
var PORT = process.env.PORT || 8080;
app.get("/", async(req,res,next) => {
res.render('index');
})
app.get("/hello", async(req, res) => {
try {
res.end(`Node Hello on ${os.hostname()}:${PORT} - ${cnt++} \n`);
} catch (err) {
console.error(err.message);
}
})
app.get("/environment", async(req, res) => {
try {
var env = process.env;
var results = "ENV\n";
Object.keys(env).forEach(function(key) {
results = results + key + ":" + env[key] + "\n";
console.log(key + ":" + env[key]);
});
res.end(results);
} catch (err) {
console.error(err.message);
}
})
app.listen(PORT, function () {
console.log('my Node app listening on PORT ' + PORT + '!');
});