-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
33 lines (24 loc) · 778 Bytes
/
server.js
File metadata and controls
33 lines (24 loc) · 778 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
'use strict'
var fs = require('fs');
var http = require('http');
var url = require('url');
var parser = require('./htmlParser');
var server = new http.Server(function (req, res) {
var parsedUrl = url.parse(req.url, true);
if (parsedUrl.path === '/') {
fs.readFile('./index.html', function (err, data) {
if (err) {
console.log(err);
res.end(err)
}
console.log('Read done! Lets parse!');
data = parser.htmlToObject(data);
res.end('<script> console.log(' + JSON.stringify(data) + ');</script>');
})
} else {
res.statusCode = 404;
res.end('<h1>Page not found</h1>');
}
});
server.listen(3000, '127.0.0.1');
//server.on('request', );