-
Notifications
You must be signed in to change notification settings - Fork 2
/
httpsrv.js
28 lines (23 loc) · 968 Bytes
/
httpsrv.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
//Lets require/import the HTTP module
var http = require('http');
//Lets define a port we want to listen to
const PORT=8080;
var ab2str = function(buf) {
var bufView = new Uint8Array(buf);
var encodedString = String.fromCharCode.apply(null, bufView);
return encodedString;
};
//We need a function which handles requests and send response
function handleRequest(request, response){
request.on('data', function (data) { console.log(ab2str(data)); });
request.on('end', function () { response.end('It Works!! Path Hit: ' + request.url); });
console.log(new Date().toLocaleTimeString() + ' - Requested: ' + request.url);
}
//Create a server
var server = http.createServer(handleRequest);
//Lets start our server
server.listen(PORT, function(){
require('dns').lookup(require('os').hostname(), function (err, add, fam) {
console.log("Server listening on: http://" + add +":%s", PORT);
})
});