forked from zhanggianluca/level8_node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
21 lines (19 loc) · 678 Bytes
/
server.js
File metadata and controls
21 lines (19 loc) · 678 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
var http = require("http");
var fs = require("fs");
var url = require("url");
http.createServer(function(request, response) {
var pathname = url.parse(request.url).pathname.substring(1);
console.log("Request for " + pathname + " received");
fs.readFile(pathname, function(err, data){
if (err) {
console.log(err);
response.writeHead(404, {"Content-Type": "text/html"});
}
else {
response.writeHead(404, {"Content-Type": "text/html"});
response.write(data.toString());
}
response.end();
});
}).listen(8081);
console.log("Server running at http://127.0.0.1:8081");