-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
34 lines (30 loc) · 921 Bytes
/
Copy pathapp.js
File metadata and controls
34 lines (30 loc) · 921 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
29
30
31
32
33
34
'use strict';
const express = require("express");
const fs = require("fs");
const path = require("path");
const app = express();
const PORT = 8083;
const HOST = "0.0.0.0";
app.use(express.static("./"));
app.get('/', function (req, res) {
console.log(req.url);
console.log("here");
res.send('Hello World!');
})
app.get("/index", function (request, response) {
console.log(request.url);
fs.readFile(path.join(__dirname, "/index.html"), 'utf8', function (err, data) {
// body
if (err) {
console.log(err); //404:NOT FOUND
response.writeHead(404, { "Content-Type": "text/html" });
} else {
//200:OK
response.writeHead(200, { "Content-Type": "text/html" });
response.write(data.toString());
}
response.end();
});
});
app.listen(PORT, HOST);
console.log(`Runnning on http://${HOST}:${PORT}`);