-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
65 lines (37 loc) · 1.27 KB
/
Copy pathindex.js
File metadata and controls
65 lines (37 loc) · 1.27 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var http = require('http'); // 1 - Import Node.js core module
var fs = require('fs');
var path = require('path');
var express = require('express');
app = express();
var login_html = "./login_page/login.html";
var dirPath = path.join(__dirname, 'login_page');
var dirJsLib = path.join(__dirname, 'js_lib');
app.use('/js_lib', express.static(dirJsLib));
app.use(express.static(dirPath));
function loginPageReq(req, res) { // 2 - creating server
var server = app.listen(80, function () {
var host = 'localhost';
var port = server.address().port;
console.log('listening on http://'+host+':'+port+'/');
});
}
loginPageReq(null, null);
/*var http = require('http'); // 1 - Import Node.js core module
var fs = require('fs');
var login_html = "./login_page/login.html";
function loginPageReq(req, res) { // 2 - creating server
//handle incomming requests here..
console.log('this is Node.js web server!');
res.writeHead(200, {'Content-Type': 'text/html'});
fs.readFile(login_html, null, function(err, data){
if(err){
res.writeHead(404);
res.write("File not found!");
} else {
res.write(data);
}
res.end();
});
}
http.createServer(loginPageReq).listen(80);
*/